Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use nUnit.Runners from NuGet

I just tried to install the nUnit test runners using nuGet, but I cannot see how to execute the test runner. When I installed the package, it seemed to run, and when I try to install from the nuget console, it indicates that the package is already installed -- but I don't see any sign of the runners.

If it matters, I run with UAC on, and I do not run VS as an admin.

NOTE: I did get this to work by installing the nUnit MSI, and I did start using the VS 2012 plug-in. However, it just bugs me that the nuget package didn't work. So, academically, I'd like to know what I was missing.

like image 217
JMarsch Avatar asked Mar 05 '13 15:03

JMarsch


People also ask

What is NUnit runner?

The nunit.exe program is a graphical runner. It shows the tests in an explorer-like browser window and provides a visual indication of the success or failure of the tests. It allows you to selectively run single tests or suites and reloads automatically as you modify and re-compile your code.

Which of the following runners are provided by NUnit?

Nunit provides three different runners, which may be used to load and run your tests. The console runner, nunit-console.exe, is used for batch execution. The gui runner, nunit.exe, provides interactive loading and running of tests.


2 Answers

The NUnit test runner actually integrates directly into the existing Visual Studio test runner (Test Explorer) (From the menu: Test->Windows->Test Explorer). As such, it doesn't show up anywhere. Just add NUnit tests to your project and they will now magically show up in the Test Explorer and run when you hit the > button.

Instead of the NuGet package, you'll need to use the test runner from the Visual Studio Gallery or from the Tools -> Extensions and Updates menu. The reason for this is that the Test Runner installs into Visual Studio (as opposed to installs into your project).

As @Jan mentions, there is now a NUnit.Runners package which you can also add to your solution. This should add the NUnit runner for commandline builds, but this does not register the NUnit VisualStudio test runner to Visual Studio. The NUnit Runners allow you to run your tests from the command line (msbuild). You can also accomplish this by running your tests using the vstest.console.exe which can be found in the Visual Studio directory: C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow.

Update

With an update to Visual Studio 2013, Microsoft has enabled test runners to be attached as NuGet packages to a project. That way they're automatically kept in sync with your project and can be set to update automatically. There is also no requirement to install the test runner on your build server.

like image 127
jessehouwing Avatar answered Oct 19 '22 04:10

jessehouwing


When you use the NuGet Pacakage Manager to install the NUnit.Runners package, it creates and populates the NUnit.Runners folder under [SolutionDir]\packages, but that folder is not automatically updated or restored on project builds, because the installer does not put an entry for NUnitRunners into the packages.config file in your project.

If you want the package to be automatically restored on builds, you can add the missing line to packages.config:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="NUnit" version="2.6.2" targetFramework="net45" />
  <package id="NUnit.Runners" version="2.6.2" targetFramework="net45" />
</packages>

I'm not sure if there is any downside to this, but is seems to work!

like image 45
Jan Hettich Avatar answered Oct 19 '22 05:10

Jan Hettich