NUnit test runners for Xamarin and mobile devices
The NuGet packages are nearly ready and we will likely create project templates, but until that is done, you will need to build from source. For this, you will need a Xamarin trial or subscription.
- Clone this repository
- Open
nunit.runner.sln
in Visual Studio with Xamarin installed, or in Xamarin Studio. - Create a release build of the solution.
Then in your solution;
- Add a new
Blank App (Android)
orBlank App (iOS)
to your solution - Add NuGet packages to your project for
NUnit 3.0.0-beta-4
andXamarin.Forms 1.4.4.6392
- Browse and add a reference to the
nunit.runner.droid.dll
ornunit.runner.ios.dll
that you built - Write your unit tests in this project, or in a shared project
- Change the base class of
MainActivity
on Android toglobal::Xamarin.Forms.Platform.Android.FormsApplicationActivity
- Change the base class of
AppDelegate
on iOS toglobal::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
- Change MainActivity.OnCreate() on Android or AppDelegate.FinishedLaunching() on iOS
- Build and run the tests on your device or emulator
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
// This will load all tests within the current project
var nunit = new NUnit.Runner.App();
// If you want to add tests in another assembly
//nunit.AddTestAssembly(typof(MyTests).Assembly);
// Do you want to automatically run tests when the app starts?
nunit.AutoRun = true;
LoadApplication(nunit);
}
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.Init();
// This will load all tests within the current project
var nunit = new NUnit.Runner.App();
// If you want to add tests in another assembly
//nunit.AddTestAssembly(typof(MyTests).Assembly);
// Do you want to automatically run tests when the app starts?
nunit.AutoRun = true;
LoadApplication(nunit);
return base.FinishedLaunching(app, options);
}