Testing .NET Core using NUnit 3

We added .NET Core (DNX) support to the RC release of NUnit 3.0, but it probably isn’t obvious on how to test your .NET Core applications. The test runner that ships with NUnit 3, nunit3-console.exe is a .NET 2.0 application that cannot run NUnit tests that reference the portable version of the framework. After the final 3.0 release, we plan on writing a DNX based runner, but until then, you can test your applications using the NUnitLite NuGet package to create self-executing tests. I will walk through doing this in Visual Studio.

The full source from this walk-through is on GitHub.

Most of the steps below are the same as for any test project, but I wanted to document everything. Similarly, I will go through the standard steps for going through running a DNX application. These will be familiar to anyone who has worked with .NET Core already, but may help new users.

I assume that you already have a project you want to test. In my case, it is just a simple Class Library (Package) with one class,

namespace MyDnxProject
    public static class Calculator
        public static int Add(int x, int y) => x + y;
        public static int Subtract(int x, int y) => x - y;
        public static int Multiply(int x, int y) => x * y;
        public static int Divide(int x, int y) => x / y;

To test this project, I simply add a new test project by right-clicking on my solution and Add | New Project…. I then navigate to the Visual C# | Web node and create a new Console Application (Package).

2015-11-04 10_59_25-Add New Project


I then add a project reference to the project under test,

2015-11-04 11_01_38-NUnitDnxTest - Microsoft Visual Studio

Next, I Manage NuGet Packages on the test project. Make sure you check Include prerelease and search for nunitlite. Adding the NUnitLite package will also pull in NUnit 3.

Now open Program.cs and replace it with the following, adjusting the namespace accordingly.

using NUnitLite;
using System;
using System.Reflection;

namespace MyDnxProject.Test
    public class Program
        public int Main(string[] args)
#if DNX451
            return new AutoRun().Execute(args);
            return new AutoRun().Execute(typeof(Program).GetTypeInfo().Assembly, Console.Out, Console.In, args);

The #if DNX451 is unfortunate, but the Console is not available in the NUnit portable library, so we need to pass it in. We hope to make this easier in the future.

Now, add test fixtures to the test project as you would with any test framework. Here are some simple ones for this test project.

using NUnit.Framework;

namespace MyDnxProject.Test
    public class CalculatorTests
        [TestCase(1, 1, 2)]
        [TestCase(-1, -1, -2)]
        [TestCase(100, 5, 105)]
        public void CanAddNumbers(int x, int y, int expected)
            Assert.That(Calculator.Add(x, y), Is.EqualTo(expected));

        [TestCase(1, 1, 0)]
        [TestCase(-1, -1, 0)]
        [TestCase(100, 5, 95)]
        public void CanSubtract(int x, int y, int expected)
            Assert.That(Calculator.Subtract(x, y), Is.EqualTo(expected));

        [TestCase(1, 1, 1)]
        [TestCase(-1, -1, 1)]
        [TestCase(100, 5, 500)]
        public void CanMultiply(int x, int y, int expected)
            Assert.That(Calculator.Multiply(x, y), Is.EqualTo(expected));

        [TestCase(1, 1, 1)]
        [TestCase(-1, -1, 1)]
        [TestCase(100, 5, 20)]
        public void CanDivide(int x, int y, int expected)
            Assert.That(Calculator.Divide(x, y), Is.EqualTo(expected));

You can now run and debug your tests from Visual Studio by setting the test project as the Startup Project and running. You may want to add the –wait command line option to the project settings under Debug | Application Arguments. This isn’t needed under .NET Core which keeps the console window open at the end of the run, but it is needed by .NET 4.5.1.

In Visual Studio, to change from running DNX 4.5.1 to DNX Core 5.0, drop down the debug project button in the toolbar and switch the CLR Type;

2015-11-04 13_55_32-NUnitDnxTest - Microsoft Visual Studio

You will notice that if you run DNX 4.5.1, you get the full colour console output, but if you switch to DNX Core 5.0, you get the same information, but in a one colour console. We hope to update NUnitLite for DNX to support full colour soon.

Now, I assume you are going to want to run your tests from the command line. The following are the steps that will be needed. All of this is just standard .NET Core stuff, but I wanted to document it for new users.

First, go into the project settings for your test project and enable Produce outputs on build for all configurations on the Build tab.

2015-11-04 14_03_55-NUnitDnxTest - Microsoft Visual Studio

Open up a command prompt and navigate to the root of your solution. .NET Core builds projects into an artifacts directory in the solution root. CD into artifacts\bin\MyDnxProject.Test\Debug. You will notice that there are NuGet packages in this folder and app, dnx451 and dnxcore50 directories.

λ ls

    Directory: D:\src\Spikes\NUnitDnxTest\artifacts\bin\MyDnxProject.Test\Debug

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       2015-11-04   2:15 PM                app
d-----       2015-11-04   2:07 PM                dnx451
d-----       2015-11-04   2:07 PM                dnxcore50
-a----       2015-11-04   2:07 PM           7018 MyDnxProject.Test.1.0.0.nupkg
-a----       2015-11-04   2:07 PM          10958 MyDnxProject.Test.1.0.0.symbols.nupkg

First run dnvm list to view the list of frameworks you have installed.

λ dnvm list

Active Version     Runtime Architecture OperatingSystem Alias
------ -------     ------- ------------ --------------- -----
       1.0.0-beta5 clr     x64          win
       1.0.0-beta5 clr     x86          win
       1.0.0-beta5 coreclr x64          win
       1.0.0-beta5 coreclr x86          win
       1.0.0-beta8 clr     x64          win             clr-x64
       1.0.0-beta8 clr     x86          win             clr-x86, default
  *    1.0.0-beta8 coreclr x64          win             coreclr-x64
       1.0.0-beta8 coreclr x86          win             coreclr-x86

Select the framework you want to run under. If it does not have a * beside it, switch to it with a command line like the following;

λ dnvm use 1.0.0-beta8 -r coreclr -a x64
Adding C:\Users\rob.prouse\.dnx\runtimes\dnx-coreclr-win-x64.1.0.0-beta8\bin to process PATH 

Next run dnu restore to fetch needed NuGet packages,

λ dnu restore
Microsoft .NET Development Utility CoreClr-x64-1.0.0-beta8-15858

  CACHE https://api.nuget.org/v3/index.json
Restoring packages for D:\src\Spikes\NUnitDnxTest\artifacts\bin\MyDnxProject.Test\Debug\app\project.json
Writing lock file D:\src\Spikes\NUnitDnxTest\artifacts\bin\MyDnxProject.Test\Debug\app\project.lock.json
Restore complete, 308ms elapsed

NuGet Config files used:

Feeds used:

You can now run your tests using the CMD file in the app folder;

λ .\app\MyDnxProject.Test.cmd
NUnitLite 3.0.5783 (Portable)
Copyright (C) 2015 Charlie Poole

Test Files

Run Settings

Test Run Summary
   Overall result: Passed
   Tests run: 12, Passed: 12, Errors: 0, Failures: 0, Inconclusive: 0
     Not run: 0, Invalid: 0, Ignored: 0, Explicit: 0, Skipped: 0
  Start time: 2015-11-04 19:58:56Z
    End time: 2015-11-04 19:58:56Z
    Duration: 0.038 seconds

Read More

Installing Google Play Services (GAPPS) on Visual Studio Android Emulators

2015-10-28 12_39_14-XDEI am developing a Xamarin application that displays maps. On Android, the map control requires that Google Play Services is installed, but most emulator images do include them. I mainly develop on Windows, so I have been using the great Visual Studio Emulator for Android. I prefer it because it is fast and uses Hyper-V. Other emulators like Xamarin’s or GenyMotion use VirtualBox under the covers which doesn’t work if you have Hyper-V enabled and I have had networking problems when it is installed and my laptop resumes from sleep.

Xamarin has a great article on how to install Google Play Services on their emulators, but it doesn’t work with the Visual Studio Emulator. I then found the solution on StackOverflow written Vijay Sargunam. His solution worked perfectly, but was missing a few steps, so the following are my modifications to his work.

  1. Download the correct GAPPS for the Android version from http://www.teamandroid.com/gapps/
  2. Use the Additional Tools (small >> icon) for the emulator and go to the SD Card tab.
  3. Select a folder on your computer to sync with the virtual SD card.
  4. Pull from SD card, which will create a folder structure on the selected folder.
  5. Now copy the Gapps fill to the ‘Download’ folder.
  6. Push to SD card. This will take a little while, and copy the zip file to your emulator.
  7. Run a commmand prompt, and go to sdk\platform-tools in your Android SDK location and run adb devices.
  8. If you see the your emulator in the list, then skip to step 10.
  9. If you do not see emulator, run the following: adb connect <emulator ip>:5555 You can find the emulator ip, from within the emulator, go to Settings -> About Phone -> Status and IP section.
  10. Next run, adb shell. This will give you a prompt to the android emulator.
  11. Confirm the gapps file is there: ls /sdcard/Download
  12. Now run, install_zip.sh /sdcard/Download/<flashablezip>.zip This should begin the flashing process.
  13. Once the flashing is complete, restart the emulator.
  14. Once you restart, you may see errors with apps like Google+ trying to start up, ignore them for now.
  15. Sign into your Google account and upgrade all apps from Google Play.
  16. When you run your application that requires Google Play services, you may be prompted to upgrade

Voilá, maps running in the emulator!

Read More

Visual Studio 2015 Cheat Sheet

Visual Studio 2015 Cheat SheetI couldn’t find an updated version of the cheat sheet for Visual Studio 2015, so I updated it myself with the new keybindings. I removed the links at the bottom to make more room. There have been several versions of this over the years. Thanks to Phil Price for the version I based this on.

You can download this as an easy to print PDF or an easy to edit Word document.

If I missed your favorite new shortcut, make sure to let me know in the comments to I can update the cheat sheet.

Read More

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)

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

On iOS:

 public override bool FinishedLaunching(UIApplication app, NSDictionary options)
     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).


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.


6. Click the Run Tests button.


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.


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.

Read More

GitHub Visual Studio Extension

I just released an Alpha release of my Visual Studio extension for working with issues on GitHub.

It allows you to access and manage GitHub issues for repositories that you have commit access to. You can filter and view issues for a repository, edit issues, add comments and close issue. This is the first Alpha release, more features are coming.


The easiest way to download is by going to Tools | Extensions in Visual Studio and searching for the GitHub Extension. It is also available in the Visual Studio Gallery and in the GitHub Releases for the project.


  • To view a list of open issues, go to View | Other Windows | GitHub Issue List (Ctrl+W, Ctrl+G)
  • Log in to GitHub by clicking the logon icon at the upper right of the issue list window
  • Open the issue window by double clicking an issue in the list, or by going to View | Other Windows | GitHub Issue Window (Ctrl+W, Ctrl+H)
  • Add a new issue to the selected repository with the + button in the issue list, or from Tools | New Issue on GitHub (Ctrl+W, Ctrl+I)
  • Edit an issue with the edit button on the Issue window
  • Add comments to, or close and issue with the comment button on the issue window



Login Window


Issue List

Issue List

Issue Window

Issue Window

Read More