This section assumes, that you already have a MSBuild build script with configured NUnit task in it, and want TeamCity to track test reports without making any changes to the existing build script. Otherwise, consider adding NUnit as one of the steps for your build configuration.
TeamCity provides custom NUnit task compatible with NUnit task from MSBuild Community tasks project. If you've configured NUnit tests in your MSBuild build script via NUnit task, TeamCity will automatically replace the original task with its own, and start command line TeamCity NUnit test launcher in order to be able to report test results. TeamCity's NUnit task 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.
note
In order for this task to work, the teamcity_dotnet_nunitlauncher system property has 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.
<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>
note
Be sure to replace "." with "_" when using Configuring Build Parameters 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 Runner for Microsoft Visual Studio 2005 and 2008 solution files. It allows you to use MSBuild-style wildcards for the assemblies to run unit tests on.
tip
Custom TeamCity NUnit task also supports additional attributes. For the list of available attributes refer to the NUnitTeamCity section.
If you need TeamCity test runner to support third-party NUnit addins, please, refer to the NUnit Addins Support section for the details.
Using NUnitTeamCity task in MSBuild Build Script
TeamCity provides custom NUnitTeamCity task compatible with NUnit task from MSBuild Community tasks project. If you'll provide NUnitTeamCity task in your build script, TeamCity will launch its own test runner based on the options specified within the task. Thus, you do not need to have any NUnit runner, because TeamCity will run the tests.
In order to correctly use NUnitTeamCity task, perform the following steps:
Make sure, the teamcity_dotnet_nunitlauncher system property is accessible on build agents. 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.
Configure your MSBuild build script with NUnitTeamCity task using the following syntax: <UsingTask TaskName="NUnitTeamCity" AssemblyFile="$(teamcity_dotnet_nunitlauncher_msbuild_task)" /><NUnitTeamCity Assemblies="@(assemblies_to_test)" />
The following attributes are supported by NUnitTeamCity task:
Property name
description
Platform
Execution mode on a x64 machine. Supported values are: x86, x64 and ANY.
RuntimeVersion
.NET Framework to use: v1.1, v2.0, v4.0, ANY. By default, the MSBuild runtime is used. Default is v2.0 for MSBuild 2.0 and 3.5. For MSBuild 4.0 default value is v4.0
List of third-party NUnit addins to be used. For more information on using NUnit addins, refer to NUnit Addins Support page.
HaltIfTestFailed
True to fail task, if any test fails.
Assemblies
List of assemblies to run tests with.
RunProcessPerAssembly
Set true, if you want to run each assembly in a new process.
Example (part of the MSBuild build script):
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <UsingTask TaskName="NUnitTeamCity" AssemblyFile="$(teamcity_dotnet_nunitlauncher_msbuild_task)"/> <Target Name="SayHello"> <NUnitTeamCity Assemblies="!!!*put here item group of assemblies to run tests on*!!!"/> </Target> </Project>
Important Notes
Be sure to replace "." with "_" when using Configuring Build Parameters in MSBuild scripts: use teamcity_dotnet_nunitlauncher_msbuild_task instead of teamcity.dotnet.nunitlauncher.msbuild.task
TeamCity also provides Solution Runner for Microsoft Visual Studio 2005 and 2008 solution files. It allows you to use MSBuild-style wildcards for the assemblies to run unit tests on.
Examples
Run NUnit tests using specific NUnit runner version.