Visual Studio 2017 comes with a great new feature called Live Unit Testing. This feature discovers and runs unit tests while you are coding, giving you inline feedback of which tests are passing, and exactly which lines are covered by the tests.
When the tests are passing you see a green tick by each line covered by at least one passing test.
When it fails you see a red cross for each line covered by the failing test, and lines that aren't covered by any tests have a blue dash.
Nunit - Why Will Visual Studio 2019 Will Not Run My Unit ...
This is a great way to get rapid feedback about the code you're currently writing. I recently attempted to get it working on a large project that had lots of NUnit tests. It's not too difficult, but there are a number of gotchas that you can run into along the way, so here's my notes for what you need to get Live Unit Testing running successfully on a project with NUnit tests.
In that case you don't need to install the vsix. This adapter only works with NUnit 3.0 and higher. For use with earlier versions of NUnit use the NUnitTestAdapter (note - no 3) extension. Version 3.9 and upwards works for Visual Studio 2012 Update 1 and higher, and Visual Studio 2013, 2015 and 2017. Version 3.13 also works with VS2019. NUnit Test Adapter 2.2: June 5, 2019: Older Releases. These releases are needed by many people for legacy work, so we keep them around for download. Bugs are accepted.
- You do need Visual Studio 2017 Enterprise Edition, so unfortunately you can't use this with the free Community Edition.
- You need to be using NUnit 3. Our tests were all in NUnit 2 and unfortunately there were quite a lot of breaking changes to work through.
- When you create a new unit test assembly, it should target either the regular .NET framework (e.g. 4.6.2) or .NET Core. Don't try to put your unit tests in a .NET Standard class library - it doesn't work (perhaps because the NUnit3TestAdapter doesn't support .NET Standard).
- Your unit test assemblies need to reference the NUnit (v3) and NUnit3TestAdapter NuGet packages
- It's not enough to have the NUnit3TestAdapter Visual Studio extension installed - that only makes your NUnit unit tests appear in the Test Explorer window. You also need to add the NUnit3TestAdapter NuGet package to your unit test project.
- If you've created a .NET Core unit test assembly you also need to reference the Microsoft.NET.Test.Sdk NuGet package
- 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 withdotnet new nunit
- There is actually a
- 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 isn't working for you.
- Live Unit Testing can be started or stopped from the Visual Studio Test menu - it doesn't run automatically.
- You may have some tests you don't want to run as part of the live unit testing. Particularly if they are 'integration' tests that might take a long time to run or communicate with external resources.
- You can right-click on tests, classes and assemblies, and include, exclude, or exclude all but this.
- Unfortunately, these settings are stored on a per-user basis so you can't share these settings with the rest of your team.
- There is a special category you can put your tests in called
SkipWhenLiveUnitTesting
which will exclude them from live testing. It's a shame you can't customize these rules to use the category names you're already using.
- Once you've got it working, I should warn you it's not all plain sailing, especially on a large solution containing thousands of tests. It often seems to get 'stuck' where it's not running tests any more, or claim that tests are 'excluded' without giving clear reasons why. There are also some cryptic errors in my live unit testing output window about an invalid filter syntax, which I don't know how to resolve. The good news is that on smaller projects it seems very responsive, and hopefully some of the quirky issues will get fixed in the near future.
Here's how quick it picks up changes when you're testing in a small project which is really nice and responsive. I don't even need to save the file:
Recommended links for further reading:
NUnit Test Adapter for Visual Studio 2012 and 2013
The NUnit Test Adapter allows you to run NUnit tests inside Visual Studio. The current release, version 0.96, is designed to work with Studio 2012 RTM, Update 1-3, and with Visual Studio 2013 Preview. Some features are not available under the RTM.
Note that Releases of Visual Studio prior to VS 2012 did not have the ability to directly run tests built with Open Source testing frameworks like NUnit.
Installation
From version 0.95 there are two ways of installing the adapter within Visual Studio. See Note 1 how to choose.
- Use the Extension Manager
- Add it as a Nuget package to your solution. (New in 0.95, require Update 1 or higher)
To install the NUnit Test Adapter using the Extension Manager, follow these steps:
- From within Visual Studio 2012 or 2013, select Tools | Extension Manager.
- In the left panel of the Extension Manager, select Online Extensions.
- Locate (search for) the NUnit Test Adapter in the center panel and highlight it.
- Click 'Download' and follow the instructions.
Use the Extension Manager to ensure that the NUnit Test Adapter is enabled.
To add it is a Nuget package, you must have an active solution, then follow these steps:
- From Tools menu, use Library Package Manager, select Manage NuGet packages for solution
- In the left panel, select Online
- Locate (search for) NUnit Test Adapter in the center panel and highlight it
- You will find two packages, one without framework and one with framework. See notes below for which to choose.
- Click 'Install'
- In the 'Select Projects' dialog, you need to select at least one project to add the adapter to, see notes below.
Note 1: How to choose between Extension and NuGet package
The Extension will apply to Visual Studio itself, and will work for all projects you use. All users of your solution needs to install the Extension. If you use TFS Build you must also install the extension to the build system there.
The Package will apply to the solution, and will work for any other user too, as it follows the solution, but requires the user to have Update 1 or above. It will also work for any TFS2012 Update 1 or above server build, including TF Service and requires no further installation.
Note 2: Choosing NuGet package
The adapter packages come with and without the NUnit framework. If you have only one test project you can choose the one with framework, that saves you from having to install both the NUnit package and the Adapter package. If you have multiple test projects you need to install the NUnit framework for all of these, but only one of these need the adapter, then choose the adapter package without framework. Installing the adapter for multiple projects will do no harm.
NUnit Version 2 Documentation Archive
Usage
Visual Studio Community For Mac How To Install Nunit Test Adapter Free
In preparation for using the test adapter, make sure that the Unit Test Explorer is shown in your window. If you don't see it, use the menu ( Test | Windows | Test Explorer ) to show it and position the window where you would like it within Visual Studio.
When you initially open a solution, no tests will be displayed. After compiling the assemblies in the solution, Visual Studio will interact with the NUnit Test Adapter to discover tests and a list of them will be shown in the Test Explorer.
Click on Run All in the Test Explorer to run all the tests. You may also select one or more tests in the list and run them by right-clicking and using the context menu. The context menu also contains entries for debugging tests and for navigating to the source code of a test.
Tests may be grouped by Duration and Outcome under VS2012 RTM and also by Traits and Project using Update 1, and Class using Update 2. NUnit translates any Categories and Properties used on your tests to Visual Studio as Traits.
Get Started With Unit Testing In Visual Studio - Visual ...
Tests may be filtered in Visual Studio under Update 1 by Trait, Project, Error Message, File Path, Fully Qualified Name, Output and Outcome. Use the search edit box at the top of the list of tests to specify a filter.
Tests may be organized by play lists in Visual Studio under Update 2. Playlists is more or less equal to the old test lists from VS 2010.
Parametrized tests, like NUnits data driven tests, will show up as seperate test cases for each set of parameters.
Known Problems
There is no test status in Visual Studio corresponding to NUnit's Inconclusive result, so tests with this result are reported as Not Run. Click on the individual test to see the result.
Grouping by fixture is not yet available.in Visual Studio.
Theories are reported as individual cases, rather as a single unit.
Startup performance is substantially improved but is still slower than using NUnit directly.
A VSIX adapter of older version will be used regardless of version of NuGet adapter.
Workaround: Make sure you have upgraded VSIX adapter to latest version, or uninstalled it if you have NuGet adapter in a solution. The 0.95 and later coming versions will output their version number in the Output window under Tests, any older versions will not have any version number there.
See More Results
Further information
The NUnit Test Adapter allows you to run NUnit tests inside Visual Studio. The current release, version 0.96, is designed to work with Studio 2012 RTM, Update 1-3, and with Visual Studio 2013 Preview. Some features are not available under the RTM.
Note that Releases of Visual Studio prior to VS 2012 did not have the ability to directly run tests built with Open Source testing frameworks like NUnit.
Installation
From version 0.95 there are two ways of installing the adapter within Visual Studio. See Note 1 how to choose.
- Use the Extension Manager
- Add it as a Nuget package to your solution. (New in 0.95, require Update 1 or higher)
To install the NUnit Test Adapter using the Extension Manager, follow these steps:
- From within Visual Studio 2012 or 2013, select Tools | Extension Manager.
- In the left panel of the Extension Manager, select Online Extensions.
- Locate (search for) the NUnit Test Adapter in the center panel and highlight it.
- Click 'Download' and follow the instructions.
Use the Extension Manager to ensure that the NUnit Test Adapter is enabled.
To add it is a Nuget package, you must have an active solution, then follow these steps:
- From Tools menu, use Library Package Manager, select Manage NuGet packages for solution
- In the left panel, select Online
- Locate (search for) NUnit Test Adapter in the center panel and highlight it
- You will find two packages, one without framework and one with framework. See notes below for which to choose.
- Click 'Install'
- In the 'Select Projects' dialog, you need to select at least one project to add the adapter to, see notes below.
Note 1: How to choose between Extension and NuGet package
The Extension will apply to Visual Studio itself, and will work for all projects you use. All users of your solution needs to install the Extension. If you use TFS Build you must also install the extension to the build system there.
The Package will apply to the solution, and will work for any other user too, as it follows the solution, but requires the user to have Update 1 or above. It will also work for any TFS2012 Update 1 or above server build, including TF Service and requires no further installation.
Note 2: Choosing NuGet package
The adapter packages come with and without the NUnit framework. If you have only one test project you can choose the one with framework, that saves you from having to install both the NUnit package and the Adapter package. If you have multiple test projects you need to install the NUnit framework for all of these, but only one of these need the adapter, then choose the adapter package without framework. Installing the adapter for multiple projects will do no harm.
NUnit Version 2 Documentation Archive
Usage
Visual Studio Community For Mac How To Install Nunit Test Adapter Free
In preparation for using the test adapter, make sure that the Unit Test Explorer is shown in your window. If you don't see it, use the menu ( Test | Windows | Test Explorer ) to show it and position the window where you would like it within Visual Studio.
When you initially open a solution, no tests will be displayed. After compiling the assemblies in the solution, Visual Studio will interact with the NUnit Test Adapter to discover tests and a list of them will be shown in the Test Explorer.
Click on Run All in the Test Explorer to run all the tests. You may also select one or more tests in the list and run them by right-clicking and using the context menu. The context menu also contains entries for debugging tests and for navigating to the source code of a test.
Tests may be grouped by Duration and Outcome under VS2012 RTM and also by Traits and Project using Update 1, and Class using Update 2. NUnit translates any Categories and Properties used on your tests to Visual Studio as Traits.
Get Started With Unit Testing In Visual Studio - Visual ...
Tests may be filtered in Visual Studio under Update 1 by Trait, Project, Error Message, File Path, Fully Qualified Name, Output and Outcome. Use the search edit box at the top of the list of tests to specify a filter.
Tests may be organized by play lists in Visual Studio under Update 2. Playlists is more or less equal to the old test lists from VS 2010.
Parametrized tests, like NUnits data driven tests, will show up as seperate test cases for each set of parameters.
Known Problems
There is no test status in Visual Studio corresponding to NUnit's Inconclusive result, so tests with this result are reported as Not Run. Click on the individual test to see the result.
Grouping by fixture is not yet available.in Visual Studio.
Theories are reported as individual cases, rather as a single unit.
Startup performance is substantially improved but is still slower than using NUnit directly.
A VSIX adapter of older version will be used regardless of version of NuGet adapter.
Workaround: Make sure you have upgraded VSIX adapter to latest version, or uninstalled it if you have NuGet adapter in a solution. The 0.95 and later coming versions will output their version number in the Output window under Tests, any older versions will not have any version number there.
See More Results
Further information
For more information see the blogs by Charlie Poole and Terje Sandstrom
Also see the following MSDN ALM blog post:
Reporting Problems
Bugs should be reported using the separate test adapterbug tracker on Launchpad.