TeamCity 2019.1 Help

NUnit

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, refer to the NUnit Support page for the details.

On this page:

NUnit 3 Requirements

Installing NUnit

To use the TeamCity NUnit build runner, install the NUnit NuGet package on TeamCity agents first using one of the following options:

  • 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:

    %teamcity.tool.NuGet.CommandLine.DEFAULT%tools\nuget.exe install NUnit.Console -version 3.6.0 -o packages

    Note that %teamcity.tool.NuGet.CommandLine.DEFAULT% is a reference to the 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.

    or

  • Install NUnit manually on all of the agents in some standard location 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

Setting

Description

NUnit runner

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

NUnit Console

Available if NUnit 3.0 is selected.

Select a preinstalled console tool or specify a custom 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 menu, select the desired execution mode on an x64 machine. Supported values are: Auto (MSIL), x86, and x64.

From the Version drop-down menu, select the required .NET Framework version. Supported values are: v2.0, v4.0; and auto, available if NUnit 3.0 is selected.
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.

**\*.dll

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.

**\obj\**\*.dll

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.

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, refer to the Configuring .NET Code Coverage page.

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


See also:

Administrator's Guide: Configuring Unit Testing and Code Coverage | NUnit Support | Getting Started with NUnit