Running NUnit with MSBuild on Windows and Mono

Last updated on

How to run unit tests using NUnit.


Create a library project called Project.Tests.

Install the NUnit package via NuGet.

Create tests.

using System;

using NUnit.Framework;

namespace Tilde.Project.Tests
    public class ClassTests
        public void UnitTest()
            Class obj = new Class();
            Assert.AreEqual("expected", obj.DoSomething());

Running tests

Visual Studio

Install the Nunit Test Runner extension in Visual Studio.

Open Test Explorer and click Run All.


Install the NUnit Runners package via NuGet.

At the following lines to your Project.Tests.csproj file at the end in <Project>:

<Target Name="RunTests" DependsOnTargets="Build">
    <ExeLauncher Condition="('$(OS)' != 'Windows_NT')">mono --runtime=v4.0.30319</ExeLauncher>
  <Exec Command="$(ExeLauncher) nunit-console.exe $(OutputPath)$(AssemblyName).dll"
        WorkingDirectory="$(SolutionDir)\packages\NUnit.Runners.2.6.3\tools" />

Run your tests with

msbuild Project.Tests.csproj /t:RunTests


You can also install NUnit on your computer. It comes with a GUI. Run the GUI and load the Project.Tests.dll assembly.