Forum Cross Platform with Xamarin

Async Testing Support across different platforms


I've set up a testing projects for my cross platform solution which currently targets Android and Win Phone. The solution contains a Core PCL and Platform specific Android and WinPhone projects. I've also created 3 test projects. The Core PCL targets the full .NET 4.5 Framework whilst the Win Phone and Android projects target their respective platforms. The Core PCL Test project uses the NUnit, the Android Test Project uses Xamarin.Android.NUnitLite and the WinPhone project uses the MS Test Platform. Using compiler directives I can share and link in the same test fixture across the different test projects. I'm also able to execute the test on the respective emulators and platforms. All seems fine, however I've running into an issue with async tests.

The test signature for a async method looks like this:

public async Task TestAsyncTableOrderBy()

This works fine when running on the full .NET 4.5 and Win Phone projects. However, when run on the Android Test Project I get a
Method has non-void return value, but no result is expected error. When I change the signature of the method to

public async void TestAsyncTableOrderBy()

it runs through successfully on the Android emulator. From reading through this blog post on Async support in NUnit (and NUnitLite) documentation I know that both async void and async Task is supported. However, it seems as if Xamarin.Android.NUnitLite only supports async void.

The MS Test Plaform does not support async void so to share the same test code across the projects, I have to use async Task. Am I missing something obvious here?


  • RobinRobin USUniversity ✭✭

    The only way I got this working is to use NUnit v2.6.2 from the command line. I don't know if NUnitLite supports async, but I do know from experience NUnit 2.6.3 broke async support.

  • CarelLotzCarelLotz ZAMember ✭✭

    Thanks for the reply. From the NUnit Lite release notes this seems to have been added already in May 2013. It might be that Xamarin still packages an older version in their Xamarin.Android.NUnitLite.dll but I read a link (can't find to it now :-( ) that the latest Xamarin toolset actually includes the latest NUnitLite version.

Sign In or Register to comment.