Note that there are some explanatory texts on larger screens.

plurals
  1. POTesting exceptions in async methods with Touch.Unit (NunitLite)
    primarykey
    data
    text
    <p>I am trying to write unit test for my async method that throws exception.</p> <p>Here is my unit test. I am expecting WebException. The test fails as WebException is not returned immediately. Test runner exits with Unhandled Exception.</p> <p>Is there any way of testing exceptions in async methods with Touch.Unit?</p> <pre class="lang-cs prettyprint-override"><code>[Test] [ExpectedException(typeof(WebException))] public async void Throws_Exception_When_GetOrders() { DataService service = new DataService(); await service.GetOrders(); } </code></pre> <p>Console output </p> <pre><code>2013-07-01 16:46:08.552 TestsiOS[32724:c07] ExceptionsTests 2013-07-01 16:46:09.855 TestsiOS[32724:c07] [FAIL] Throws_Exception_When_GetOrders : System.Net.WebException was expected ... Unhandled Exception: System.Net.WebException: Error: NameResolutionFailure at System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult) [0x00065] in /Developer/MonoTouch/Source/mono/mcs/class/System/System.Net/HttpWebRequest.cs:947 at RestSharp.Http.GetRawResponseAsync (IAsyncResult result, System.Action`1 callback) [0x00000] in &lt;filename unknown&gt;:0 ... </code></pre> <p>I have tried to return Task in my test method. It simply ignores my test method. </p> <pre><code>public async Task Throws_Exception_When_GetOrders() </code></pre> <p>I have also tried this. And the test run hangs up. </p> <pre><code>public void Throws_Exception_When_GetOrders() { DataService service = new DataService(); service.GetOrders().Wait(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload