Visual Studio Community For Mac How To Install Nunit Test Adapter



  • There is actually a dotnet new template you can install so that you can easily create a.NET core unit test assembly with the correct references for live testing in NUnit 3 with dotnet new nunit The Visual Studio Output window with 'Live Unit Testing' selected in the dropdown is a good place to look when troubleshooting why Live Unit Testing.
  • The NUnitTestAdapter extension works with the Visual Studio Unit Test window to allow integrated test execution under Visual Studio 2012, 2013, 2015 and 2017. The latest version, 2.0, is based on NUnit 2.6.4 and is compatible with tests developed using NUnit 2.0 through 2.6.4.

An extension that adds Project and Item templates to Visual Studio along with Code Snippets to make unit testing with NUnit 3 easier.

The project currently provides the following templates.

Project Templates

TemplatePlatformLanguage
NUnit 3 Unit Test ProjectDesktopC#
NUnit 3 Unit Test ProjectDesktopVisual Basic
NUnit 3 Unit Test ProjectXamarin Android1C#
NUnit 3 Unit Test ProjectXamarin iOS1C#
NUnit 3 Unit Test ProjectXamarin UWP1,2C#

1Requires Xamarin for Visual Studio be installed.
2Requires the Windows 10 SDK be installed.

For more information on Xamarin testing, see Testing Xamarin Projects using NUnit 3.

Item Templates

TemplateLanguageDescription
NUnit Test FixtureC#An NUnit unit test class
NUnit Test FixtureVisual BasicAn NUnit unit test class
NUnit SetUp FixtureC#Code that runs before and after all the tests in the assembly
NUnit SetUp FixtureVisual BasicCode that runs before and after all the tests in the assembly

Code Snippets

SnippetShortcutLanguage
Test FixturentestfixtureC#
Test MethodntestC#
Test CasentestcaseC#

Don't see the template you need or your favorite code snippet? All you need to do is fork the repository on GitHub, add it and create a pull request. We love help and contributions.

Let’s see how to add supporting of NUnit to the Visual Studio 2015 project. I will describe a simple example without unnecessary things.

I have Visual Studio 2015. I want to add NUnit's tests for C# project with NuGet Package Manager, and I want to have possibility of running tests with Visual Studio and in Visual Studio. First I create new C# project: menu File → New → Project → Installed → Templates → Visual.

At first step let’s create a simple console application with name test_unit and add new class to it with name Class1 as shown below

Below is code of class Class1

Visual Studio Community For Mac How To Install Nunit Test AdapterNunit

There is method isValidLogFileName which returns false if extension of file isn’t end with “log” and false elsewhere.

At the second step we have to create library which will tests our class. Thus create another project in our solution with test project name + “.UnitTests” as shown below

Create class that will be used for testing with name of tested class + Tests. Our class is Class1 so the class for testing should be Class1Tests and code to the created class should be as shown below

At the third step we have to install NUnit trough Visual Studio package manager using command

Install-Package NUnit

After this you will find in your project hierarchy directories dll files which realize NUnit functionality as shown below

In theory package manager should add reference to one of the dll automatically but in my case this hasn’t happened so I just added reference to net45 nunit.framework.dll manually (you should add reference to the nunit.framework.dll only for library used for testing). Also we have to add reference to the project that will be tested (without that we can’t create object of tested class).

At the fourth step we have to install NUnit Test Adapter. This adapter allow us run test in Visual Studio. Also we can use difference approaches including commercial products to achieve that but this is very easy as I think. To install NUnit Test Adapter go to “Tools Extensions and Updates”. Then select “online extensions” and find NUnit Test Adapter as shown below and then download and install this one.

C# - Install NUnit with Visual Studio 2017 - Stack Overflow

After we need to restart Visual Studio in order for the changes to take effect.

And finally we can run our tests. Just go to “Test / Run / All tests” or press Cntrl+R, A. We will see that all test are passed.

Let’s make bug in our isValidLogFileName function. Just remove ! before logFileName. Now our tests are not passed.

NUnit Version 2 Documentation Archive

Take a look at the names of test methods used by NUnit framework. The name should be “tested function name”_”Scenario under test”_”Expected behavior”.