TeamCity
 
You are viewing the documentation for an earlier version of TeamCity.

.Net Testing Frameworks Support

Last modified: 20 April 2023

In order to support tests reporting, TeamCity should either plugin into the testing frameworks to receive notifications on tests events or run the tests by own test runner. Bundled supported for the tests frameworks is implemented using custom TeamCity-aware tests runner.

Supported frameworks:

  • NUnit (2.2.x, 2.4.x)

  • MSTest

Integration with Build Runners



NAnt Runner



TeamCity provides custom task implementation. TeamCity automatically replaces original nunit2 task on it's own task, so if your build script uses nunit2 task, it will automatically work without any modifications to the build script.

Since TeamCity 3.1, the following options are supported for TeamCity <nunit2> task implementation:

We've also added support for NAnt 0.86 runner and NUnit 2.4 testing framework.

TeamCity NUnit test launcher will run tests in .NET Framework which is specified by NAnt target framework, i.e. on .NET Framework 1.1 or .NET Framework 2.0 runtime.

TeamCity 3.1. also supports test categories for <nunit2> task.

MSBuild Runner



TeamCity provides custom NUnitTeamCity task.

The MSBuild NUnit task is a convenient way to run the tests for MSBuild and Solution 2005 builds. Example usage is (part of the MSBuild build script):

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <UsingTask TaskName="NUnit" AssemblyFile="$(teamcity_dotnet_nunitlauncher_msbuild_task)"/> <Target Name="SayHello"> <NUnit Assemblies="!!!*put here item group of assemblies to run tests on*!!!"/> </Target> </Project>

Since TeamCity 3.1, NUnitTeamCity task supports extra arguments to the NUnitTeamCity task:

TeamCity NUnit launcher



TeamCity uses own NUnit tests launcher that can be used without any support from the runner. The tests are run according to the passed parameters and if the process is run inside TeamCity build agent environment, the results are reported to the TeamCity agent.

Inside the build run by TeamCity the name of the NUnit launcher can be obtained through the system properties and environment variables. Please note that TeamCity 3.0 and 3.1 versions use different properties to pass the launcher name.

The launcher can be used in the build script to run the tests. e.g. here is an example for NAnt script (as of TeamCity 3.0):

<exec program="${teamcity.dotnet.nunitlauncher<version>}"> <arg file="MyAssemblyToTest.dll"/> <arg file="MyAssemblyToTest2.dll"/> </exec>

TeamCity 3.0



The properties are available as both environment variables and system properties of the build system (NAnt, MSTest) teamcity.dotnet.nunitlauncher1.1 - full launcher application name for .Net Framework 1.1 teamcity.dotnet.nunitlauncher2.0 - full launcher application name for .Net Framework 2.0 teamcity.dotnet.nunitlauncher2.0.vsts - full launcher application name for .Net Framework 2.0 for VSTS tests support

The command line syntax is as follows:

%teamcity.dotnet.nunitlauncher<version>% MyAssemblyToTest1 MyAssemblyToTest2

TeamCity 3.1



The property is available as both environment variables and system properties of the build system (NAnt, MSTest) teamcity.dotnet.nunitlauncher - full launcher application name

The launcher supports the following command line options:

${teamcity.dotnet.nunitlauncher} [v1.1|v2.0] [x86|x64|MSIL] [NUnit-2.2.10|NUnit-2.2.9-VSTS|NUnit-2.4.6] <assemblies to test>

where

  • v1.1 and v2.0 are version of .NET Framework to run tests

  • x86, x64 and MSIL are platforms to run tests, note, for .NET Framework 1.1 it only possible to use MSIL

  • NUnit-2.2.10, NUnit-2.2.9-VSTS and NUnit-2.4.6 are test frameworks to use

Note NUnit-2.2.9-VSTS is a modified version of NUnit to run Microsoft Visual Studio Team System Tests (for Microsoft Visual Studio 2005)