TeamCity Cloud 2021.1 Help

NUnit for NAnt Build Runner

This section assumes, that you already have a NAnt build script with the configured nunit2 task in it, and want TeamCity to track test reports without making any changes to the existing build script. Otherwise, consider adding NUnit build runner as one of the steps for your build configuration.

To track tests defined in a NAnt build via the standard nunt2 task, TeamCity provides a custom task implementation and automatically replaces the original <nunit2> task with its own task. Thus when the build is triggered, TeamCity starts TeamCity NUnit Test Launcher using own implementation of <nunit2>. This allows you to leave your build script without changes and receive on-the-fly test reports in TeamCity.

If you don't want TeamCity to replace the original nunit2 task, consider the following options:

  • Use NUnit console with TeamCity Addin for NUnit.

  • Import XML tests results via the XML Test Report plugin.

  • Use command-line TeamCity NUnit Test Launcher.

  • Configure reporting tests manually via service messages.

  • To disable nunit2 task replacement, set teamcity.dotnet.nant.replaceTasks system property to false.

The nunt2 task implementation in TeamCity supports additional options that can be specified either as NAnt <property> tasks in the build script, or as System Properties under Build Configuration | Build Parameters.

The following options are supported for the TeamCity <nunit2> task implementation:

Property

Description

teamcity.dotnet.nant.nunit2.failonfailureatend

Run all tests regardless of the number of failed ones, and fails if at least one test has failed.

teamcity.dotnet.nant.nunit2.platform

Sets desired runtime execution mode for .NET 2.0 on x64 machines. Supported values are x86, x64, and ANY (default).

teamcity.dotnet.nant.nunit2.platformVersion

Sets desired .NET Framework version. Supported values are v1.1, v2.0, v4.0. Default value is equal to NAnt target framework

teamcity.dotnet.nant.nunit2.version

Specifies which version of the NUnit runner to use. The value has to be specified in the following format: NUnit-<version>.

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

teamcity.dotnet.nant.nunit2.addins

Specifies the list of third-party NUnit addins used for NAnt build runner.

teamcity.dotnet.nant.nunit2.runProcessPerAssembly

Set true if you want to run each assembly in a new process.

TeamCity NUnit test launcher will run tests in the .NET Framework, which is specified by NAnt target framework, i.e. on .NET Framework 1.1, 2.0 or 4.0 runtime. TeamCity also supports test categories for <nunit2> task.

Examples

Start tests form a single assembly files under x64 mode on .NET 2.0.

<property name="teamcity.dotnet.nant.nunit2.platform" value="x64" /> <nunit2> <formatter type="Plain" /> <test assemblyname="MyProject.Tests.dll" /> </nunit2>

Run all tests from category C1, but not C2.

<nunit2 verbose="true" haltonfailure="false" failonerror="true"> <formatter type="Plain" /> <test> <assemblies> <include name="dll.dll" /> </assemblies> <categories> <include name="C1" /> <exclude name="C2"/> </categories> </test> </nunit2>

Explicitly specify the version on NUnit to run tests with.
Note, that in this case, the following property should be added before the nunit2 task call.

<property name="teamcity.dotnet.nant.nunit2.version" value="NUnit-2.4.10" /> <nunit2> <!--....--> </nunit2>
Last modified: 23 July 2020