NUnit 3.0 Test Runner for Android and iOS

We are busy preparing the long awaited beta release of NUnit 3.0 that should ship this week, but I’ve also been working on NUnit 3 runners for Android and iOS using Xamarin. It is still early days, but it is working fairly well, so I wanted to show it off and hopefully get some feedback on it. Windows phone will follow shortly and I will update it to support other platforms like Windows Store when Xamarin’s support moves from early preview to beta.

The following is the current process.

1. Creates a Xamarin Android or iOS application project. I hope to create a project template eventually.

2. Reference nunit.runner and nunit.framework in the project. It will be a NuGet package with the correct Xamarin dependencies.

3. In MainActivity.OnCreate() on Android or AppDelegate.FinishedLaunching() on iOS, swap the App object with the one we provide.

On Android:

 protected override void OnCreate(Bundle bundle)
 {
    base.OnCreate(bundle);

    global::Xamarin.Forms.Forms.Init(this, bundle);
    LoadApplication(new NUnit.Runner.App());
 }

On iOS:

 public override bool FinishedLaunching(UIApplication app, NSDictionary options)
 {
     global::Xamarin.Forms.Forms.Init();
     LoadApplication(new NUnit.Runner.App());

     return base.FinishedLaunching(app, options);
 }

4. Write unit tests in the current assembly, or if you have tests in another referenced assembly, add those assemblies in App.AddTest(Assembly testAssembly).

Screenshot_2015-03-25-18-36-39

5. Build and deploy the test app. When you launch it, it looks like this. The icon is generic because it comes from the project you created. If I create a template, then I will replace it with the NUnit icon.

Screenshot_2015-03-25-18-36-43

6. Click the Run Tests button.

Screenshot_2015-03-25-18-36-49

7. You get the typical overall summary of the test run. You can then drill down into just the failed or all tests. I might change the wording on those bottom buttons.

Screenshot_2015-03-25-18-36-59

8. You see a scrolling list of all tests. The colored text is the test name. I just named some Fail, Error, etc so I could quickly eyeball mistakes 🙂 You can then drill down into the individual tests for more information.

Of course, you can navigate up and down the stack and re-run tests. Some frameworks allow you to re-run individual tests. I’m not sure how useful that is, so I am holding off on that.