TeamCity Cloud 2023.09 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 and supported versions.

Note that this runner supports only .NET Framework. To run tests for .NET Core projects (and .NET Framework projects version 4.0 or later), use the .NET build runner with the test command instead. See the NUnit Support in TeamCity article for details.

Installing NUnit

To use the NUnit build runner, you need to install the NUnit NuGet package on TeamCity agents via one of the following options:

  • Instruct the first build step to install NUnit from a NuGet package.
    For example, you can add a Command Line 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 on the Administration | Tools page, where you can also mark any 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 package directory.

  • Install NUnit manually to a standard location on all the build agents 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.
If the extensions 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 will be displayed suggesting you install them.

The extensions can be installed as separate packages or in bulk using the NUnit Console Version 3 NuGet package.

NUnit Test Settings

Setting

Description

NUnit runner

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

NUnit Console

Available for NUnit 3.0

Select a preinstalled console tool or specify a custom path to the nunit3-console.exe console executable, including the filename.

Working directory

Available for NUnit 3.0

Specify the path to the build working directory if it differs from the directory of the testing assembly.

Path to application configuration file

Available for NUnit 3.0

Specifу the path to the application configuration file to be used when running tests. The path should be either absolute or relative to the checkout directory.

Additional command line parameters

Available for NUnit 3.0

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 stored. Multiple entries should be comma-separated. The MSBuild wildcards are supported. The paths to assembly files should be absolute or relative to the checkout directory.

In the example, TeamCity will search for the tests assemblies in all the project directories and run these tests:

**\*.dll

Wildcards are specified relatively 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 should be comma-separated. The MSBuild wildcards are supported. The paths to assembly files should be absolute or relative to the checkout directory.

In the example, TeamCity will omit tests specified in this directory:

**\obj\**\*.dll

Wildcards are specified relatively to the checkout directory.

Include categories

Specify NUnit categories of tests to be run. Multiple entries should be comma-separated.
Category expressions are supported 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 should be 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.

NUnit Code Coverage

To learn about configuring code coverage options, refer to the this article.

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

Last modified: 25 January 2022