Skip to end of metadata
Go to start of metadata

The NUnit build runner is intended to run NUnit tests right on the TeamCity server. However, there are other ways to report NUnit tests results to TeamCity, please refer to the NUnit Support page for the details.

Icon

Supported NUnit versions: 2.2.10, 2.4.1, 2.4.6, 2.4.7, 2.4.8, 2.5.0, 2.5.2, 2.5.3, 2.5.4, 2.5.5, 2.5.6, 2.5.7, 2.5.8, 2.5.9, 2.5.10, 2.6.0, 2.6.1, 2.6.2, 2.6.3. Since TeamCity 9.1, NUnit 3.0 and above is also supported.

It is possible to have several versions of NUnit installed on an agent machine and use any of them in a build.

Icon

NUnit version 3.4.0 is not supported by the NUnit build runner due to a problem in NUnit. Only version 3.4.0 was affected, other NUnit 3.x versions work fine with TeamCity.


NUnit 3 Requirements

Installing NUnit

To use the TeamCity NUnit build runner, you need to install the NUnit NuGet package on TeamCity agents first.

To do that, use one of the following options:

  • you can add the NuGet install build step as the first step of your build configuration.
    For example, you can add a command line build step before the NUnit build step which will install the NUnit.Console NuGet package as follows:


    Note that %teamcity.tool.NuGet.CommandLine.DEFAULT% is a reference to NuGet installed under the TeamCity agent.
    You can install NuGet on agents from the Administration | Tools page, where you can also mark one of the installed NuGet versions as default.

    After that the %teamcity.tool.NuGet.CommandLine.DEFAULT% parameter reference should properly resolve to the NuGet installation path on the agent.
    Then nunit3-console should appear under the packages directory.

    To run tests, in the next NUnit build step, specify the NUnit path in the NUnit settings as packages\NUnit.ConsoleRunner.3.6.0\tools\nunit3-console.exe.
     

  • Another approach is to install NUnit manually on all of the agents in some standard place, and configure the path to nunit-console.exe in your NUnit build step.
 

 

Installing Extensions

Starting from version 3.2.0, NUnit requires the NUnit.Extension.NUnitProjectLoader extension to be installed on the TeamCity agent. 
Starting from version 3.4.1, NUnit requires the NUnit.Extension.TeamCityEventListener extension to be installed on the TeamCity agent.

The NUnit runner checks for the extensions, and if they are not found, in versions 3.2.0 and 3.2.1 the build will fail without a warning; since version 3.4.1 a message is displayed suggesting you install them. 
The extensions can be installed in bulk using the NUnit Console Version 3 NuGet package or as separate packages, NUnit.Extension.TeamCityEventListener and NUnit.Extension.NUnitProjectLoader.

NUnit Test Settings

NUnit runner

Select the NUnit version to be used to run the tests. The number of settings available will vary depending on the selected version.

Path to NUnit console tool:

Available if NUnit 3.0 is selected. Specify the path to nunit3-console.exe:

prior to TeamCity 9.1.4 specify the directory containing the console executable file,
since 9.1.4
 specify the path to the console executable file including the file name. 
Working directory Available if NUnit 3.0 is selected. Optional. Specify the path to the build working directory if it differs from the directory of the testing assembly.

Path to application configuration file

Available if NUnit 3.0 is selected. Specifу the path to the application configuration file to be used when running tests. The path is absolute or relative to the checkout directory.

Additional command line parameters

Available if NUnit 3.0 is selected. Enter additional command line parameters to pass to nunit-console.exe

.NET Runtime

From the Platform drop-down, select the desired execution mode on a x64 machine. Supported values are: Auto (MSIL), x86 and x64.
From the Version drop-down, select the desired .NET Framework version. Supported values are: v2.0, v4.0; and <auto>, available if NUnit 3.0 is selected.
(info) For NUnit 3.0, if <auto> is selected, tests will run under the framework they are compiled with.

Run tests from

Specify the .NET assemblies where the NUnit tests to be run are stored. Multiple entries are comma-separated; usage of MSBuild wildcards is enabled. The paths to assembly files are absolute or relative to the checkout directory.
In the following example, TeamCity will search for the tests assemblies in all project directories and run these tests.

Icon

All these wildcards are specified relative to the checkout directory.

Do not run tests from

Specify .NET assemblies that should be excluded from the list of assemblies to test. Multiple entries are comma-separated; usage of MSBuild wildcards is enabled. The paths to assembly files are absolute or relative to the checkout directory.
In the following example, TeamCity will omit tests specified in this directory.

Icon

All these wildcards are specified relative to the checkout directory.

Include categories

Specify NUnit categories of tests to be run. Multiple entries are comma-separated.

Category expressions are supported here as well; commas, semicolons, and new-lines are treated as global or operations (prior to the expression parsing). Since NUnit 3.0 category expressions are not supported and must be set via the command line as described in the NUNit documentation.

Exclude categories

Specify NUnit categories to be excluded from the tests to be run. Multiple entries are comma-separated.

Category expressions are supported here as well; commas, semicolons, and new-lines are treated as global or operations (prior to the expression parsing). Since NUnit 3.0 category expressions are not supported and must be set via the command line as described in the NUNit documentation.

Run process per assembly

Available for versions prior to NUnit 3.0 only (since TeamCity 9.1.6). Select this option if you want to run each assembly in a new process.

Reduce test failure feedback time

Use this option to instruct TeamCity to run some tests before others.

Code Coverage

To learn about configuring code coverage options, please refer to the Configuring .NET Code Coverage page.

(info) For NUnit 3.x, only JetBrains dotCover is supported as a coverage tool.

See also:

  • No labels

7 Comments

  1. If like me you think it is silly to have to specify the path to the Nunit3-console.exe when this path changes depending on the version you have installed and whether it came from an .msi or was required via packages.config, you can use the PowerShell from this post on StackOverflow to find any version of Nunit installed via the latter requirement.

    http://stackoverflow.com/a/38862220/3794873

    1. dragon788, we are working on implementing an alternative approach when you can select the NUnit version to use globally on all the agents (the way it is currently done for NuGet). It will resolve any inconveniences you might be experiencing at the moment. 

      1. Thanks Julia, this is good to know. My main concern would be that if the Nunit 3 version is defined outside of the project/solution (ie by TeamCity globally) then the version the developers are testing and building against locally will NOT be the same as the one they are interacting with on the CI system. That is why I'll probably continue to use the method I linked above where the developers add the Nunit 3.x package and Nunit.Console to their solution and then our TeamCity through a build step detects and utilizes the project specific version rather than dictating one version for all projects to use.

      2. One year later, how is this going? Still having to manually update this path when we update the package.

  2. We recently updated from TeamCity 9 to TeamCity 10. It seems that our test with TeamCity 9 were being parallelized and aren't anymore (time to execute our test bumped from 4 minutes to 14 minutes after the update). Is there an option to give to TeamCity to execute nunit tests in parallel? 

  3. %teamcity.tool.NuGet.CommandLine.DEFAULT%toolsnuget.exe install NUnit.Console -version 3.6.0 -o packages

    This should actually be: %teamcity.tool.NuGet.CommandLine.DEFAULT%\tools\nuget.exe install NUnit.Console -version 3.6.0 -o packages

    and 

    • To run tests, in the next NUnit build step, specify the NUnit path in the NUnit settings as 
packagesNUnit.ConsoleRunner.3.6.0toolsnunit3-console.exe.

    Should be: packages\NUnit.ConsoleRunner.3.6.0\tools\nunit3-console.exe

    1. Eric, thanks a lot for noticing this! I fixed the paths.