Following the release of xUnit 2.0 RC3, the Xamarin Device Runners have been updated to work with RC3.
One note for Android users: due to a dependence on Xamarin Forms, your runner app project needs to use API level 21 as its target and SDK. You can target down to API level 15 if you wish. You can also reference other MonoAndroid or Portable Class Libraries if you want to keep your unit tests at a different API level. You also might need to specify a default theme on some devices to workaround a different Xamarin Forms bug. Please see the updated MainActivity.cs.txt
for the specifics.
Wait, what happened to RC2?
If you blinked, you missed it. RC2 of the Device Runners came out Saturday. With xUnit RC3 being a quick update from RC2, it’s best to skip to the latest.
As always, if you run into any issues, feel free to reach out to @onovotny on Twitter or post an issue on GitHub.
Getting Started
RC3 is available on NuGet and on GitHub.
For iOS and Android, create a new blank Xamarin app project to host the unit test runner. Make sure to give any capabilities/permissions you need in the appropriate manifest.
For WP8, create a new Unit Test Project and then remove the MSTestFramework reference.
Then for all platforms, install/update the xUnit.Runner.Xamarin
package via the GUI or Package Manager Console
:
Install-Package xunit.runner.xamarin -Pre
Then look for the .cs.txt
, xaml.txt
files that are the templates for your platform and copy/paste the contents into the app. Specifically,
– iOS: replace the contents of AppDelegate.cs
with AppDelegate.cs.txt
– Android: replace the contents of MainActivity.cs
with MainActivity.cs.txt
– WP8: replace the contents of MainPage.xaml.cs
with MainPage.xaml.cs.txt
and MainPage.xaml
with MainPage.xaml.txt
Hi Oren,
What sort of testing is possible using the runner? I want to be able to test Activities and Services in my current Android app project – I don’t see how I could do this with the method outlined above (as one app project cannot depend upon another).
Ideally I want to be able manipulate the UI and make assertions about events happening on a mocked-out back-end. Is this possible at all with Xamarin.Android? Xamarin UITest allows UI manipulation but doesn’t allow you to mock out the backend (it’s blackbox only).
If you know of any example projects around the Net that use this runner and test Android components then please send me a link! It would be much appreciated.
Many thanks
Mike