NUnit for MSBuild

You are viewing documentation of TeamCity 4.x, which is not the most recent released version of TeamCity. Please refer to the listing to choose another version.
Search
Searching TeamCity 4.x Documentation
Table of Contents

TeamCity provides custom NUnitTeamCity task and NUnit task that is compatible with NUnit task from MSBuild Community tasks project.

In order for these tasks to work the teamcity_dotnet_nunitlauncher system property have to be accessible. Build Agents running windows should automatically detect these properties as environment variables. If you need to set them manually, see defining agent specific properties for more information.

The NUnit/NUnitTeamCity task uses the following syntax:

<UsingTask TaskName="NUnit" AssemblyFile="$(teamcity_dotnet_nunitlauncher_msbuild_task)" />

The NUnit/NUnitTeamCity task tests .NET Assemblies with NUnit. Add the following code to your target in MSBuild script to implement it:

<NUnitTeamCity Assemblies="@(assemblies_to_test)" />

This NUnit task is automatically included in MSBuild and Solution2005 and Solution2008 builds.

TeamCity uses its own version of NUnit task for running NUnit tests. TeamCity version is compatible with the MSBuild Community Task and will issue a warning, if TeamCity does not support an attribute listed in the build script. These warnings are only for your information and will not affect the building process.

The NUnitTeamCity task supports the following extra attributes:

Property name description
Platform Specifies the desired execution mode on a x64 machine. Supported values are: x86, x64 and ANY.
IncludeCategory ; separated list of categories
ExcludeCategory ; separated list of categories
NUnitVersion Specifies which version of NUnit to run the tests.
NUnit versions support
TeamCity NUnit Test Launcher supports NUnit versions 2.2.10, 2.4.1, 2.4.6, 2.4.7, 2.4.8, and 2.5.0.
TeamCity Addin for NUnit supports only 2.4.6, 2.4.7, 2.4.8, and 2.5.0.
TeamCity 4.5.6+ supports NUnit 2.5.2, and 2.5.3.
Addins Specifies a list of NUnit addins to use
HaltIfTestFailed True to fail task is there were failed tests
Assemblies List of assemblies to run tests with
In TeamCity 4.5, ExitCode output attribute is added to the <NUnit> task. Exit code is '0', if there were no crashes and runner exceptions. Otherwise non-zero exit code is returned.

Example usage is shown below (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>
  • Be sure to replace "." with "_" when using Properties of a Build Configuration in MSBuild scripts. That is you have to use teamcity_dotnet_nunitlauncher_msbuild_task instead of teamcity.dotnet.nunitlauncher.msbuild.task
  • TeamCity also provides 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.


Labels