.NET Testing Frameworks Support

You are viewing documentation of TeamCity 3.x, which is not the most recent released version of TeamCity. Please refer to the listing to choose another version.
Documentation Index

.NET Testing Frameworks Support

In order to support the real-time reporting test results, TeamCity should either run the tests using its own test runner or be able to interact with the testing frameworks so it receives notifications on test events. Custom TeamCity-aware test runners are used to implement the bundled support for the testing frameworks.

The following frameworks are supported:

  • NUnit 2.2.x
  • NUnit 2.4.x (since TeamCity 3.1)
  • MSTest

This section covers:

TeamCity 3.0

TeamCity NUnit Test Launcher

TeamCity uses its own NUnit tests launcher that can be used from the any 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.

The properties are available as both environment variables and system properties are available under any build process running on TeamCity, e.g. NAnt, MSBuild, Ant, SimpleRunner, etc.

teamcity.dotnet.nunitlauncher1.1 - full launcher application name for .Net Framework 1.1, NUnit 2.2.8
teamcity.dotnet.nunitlauncher2.0 - full launcher application name for .Net Framework 2.0, NUnit 2.2.8
teamcity.dotnet.nunitlauncher2.0.vsts - full launcher application name for .Net Framework 2.0, VSTS tests

Starting from TeamCity 3.1.x these properties are considered obsolete.

Inside the build run by TeamCity the name of the NUnit launcher can be obtained through the system properties and environment variables.

The command line syntax is as follows:

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

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>

NAnt Runner

TeamCity provides custom <nunit2> task implementation. TeamCity automatically replaces the original <nunit2> task with its own task, so if your build script uses the nunit2 task, it will automatically work without any modifications to the build script.

MSBuild Runner

TeamCity provides custom NUnitTeamCity task and NUnit task that is compatible with NUnit task from MSBuild Community tasks project.
The MSBuild NUnit/NUnitTeamCity tasks are 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>
  • Make sure to replace "." with "_", when using properties in MSBuild scripts. (i.e. use teamcity_dotnet_nunitlauncher_msbuild_task instead of teamcity.dotnet.nunitlauncher.msbuild.task)
  • TeamCity also provides a Solution 2005 Runner for Microsoft Visual Studio 2005 solution files. It allows you to use MSBuild-style wildcards for the assemblies to run unit tests on.

TeamCity 3.1

NAnt Runner

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

Property name description
teamcity.dotnet.nant.nunit2.failonfailureatend Run all tests 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.version Specifies which version of the NUnit runner to use. Supported versions are:
NUnit-2.2.10 (default), NUnit-2.2.9-VSTS and NUnit-2.4.6.

TeamCity 3.1 also supports the NAnt 0.86 runner and the NUnit 2.4 testing framework.

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 or .NET Framework 2.0 runtime. TeamCity 3.1. also supports test categories for <nunit2> task.

Shown properties can be using <property> task of NAnt or using TeamCity system properties under runner configuration.

MSBuild Runner

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

Property name description
Platform Specifies the desired execution mode on a x64 machine. Supported values are: x86, x64 and ANY.
IncludeCategory As used in the original task
ExcludeCategory As used in the original task
NUnitVersion Specifies which version of NUnit to run the tests. Supported values are: NUnit-2.2.10 (default), NUnit-2.2.9-VSTS, NUnit-2.4.6.

TeamCity NUnit Launcher

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

TeamCity 3.1 is backward compatible to TeamCity 3.0, thus it still defines the set of properties teamcity.dotnet.nunitlauncher<version>, but now those properties are obsolete.

The launcher supports the following command line options:

${teamcity.dotnet.nunitlauncher} [<.NET Framework>] [<platform>] [/category-include:<list>] [/category-exclude:<list>] [<NUnit vers.>] <assemblies to test>

where

  • <.NET Framework> is the version of .NET Framework to run tests. Possible values are 1.1 or 2.0.
  • <platform> — platform to run tests. Possible values: x86, x64 and MSIL.
    For .NET Framework 1.1 it is only possible to use MSIL platform.
  • <NUnit vers.> is the test framework to use. Possible values: NUnit-2.2.10, NUnit-2.2.9-VSTS and NUnit-2.4.6
  • <list> is the list of categories separated by ';'.
  • <assemblies to test> is the list of assemblies paths separated by ';' or space.

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

See also:

Labels