Features FYI How-To's Tips & Tricks

Using TeamCity NUnit Launcher

After not so short break we are back with the next post of our .NET mini-series, and today we are going to tell you about TeamCity NUnit Launcher — a bundled NUnit test runner. In most cases, if you need to use NUnit, all you have to do is just to run it with this Launcher.

As we said in the previous post, to provide tests state tracking and on-the-fly reporting, TeamCity contains several NUnit builds (different NUnit versions) and provides NUnit Launcher to use particular NUnit build for your tests.

To start the NUnit Launcher from any TeamCity build runner, use either the teamcity.dotnet.nunitlauncher NAnt property, or the environment variable of the same name, or the teamcity_dotnet_nunitlauncher MSBuild property. These properties should have the following mandatory parameters:

  • .NET Framework version (both 1.1 and 2.0 versions are supported),
  • The platform to run tests (x86, x64, and MSIL),
  • The test framework version to use. TeamCity supports the following NUnit versions: 2.2.10, 2.4.1, 2.4.6, 2.4.7, 2.4.8, and 2.5.0 (Alpha 3)
  • List of assemblies to test

In addition to the above-mentioned parameters, you can also specify filters by tests category and NUnit addins (for NUnit 2.4 and higher). Filters by tests category allow you to control a set of tests to run, if you use tests grouping by category in your project.

You can find the detailed description of TC NUnit Launcher syntax at TeamCity reference. Here, in this post, we will just illustrate it with the example below.

The following example shows variations of TeamCity NUnit Launcher calls to run tests with NUnit.
Let’s assume, our task has the following initial conditions (all code samples below are true to these conditions):

  • You want to run the project using an MSBuild runner
  • Assemblies to test are placed into the assemblies and assemblies.lib folders
  • Tests are grouped by following categories: ‘test‘, ‘lib‘, ‘banned
  • You use the .NET Framework, version 2.0
  • Platform is x86
  • NUnit version is 2.5.0 (Alpha 3)

In the most simple case, you have to include the following lines to your MSBuild script to run tests:

<ItemGroup>
  <TestAssemblies Include="assemblies\test*.exe"/>
  <TestAssemblies Include="assemblies.lib\test*.exe"/>
</ItemGroup>

<Target Name="runTests">
  <Exec Command="$(teamcity_dotnet_nunitlauncher) v2.0 x86 NUnit-2.5.0 @(TestAssemblies)" />
</Target>

For a bit more complex processing, you can filter the assemblies to test by category. For example, let’s run tests from the ‘test‘ and ‘lib‘ categories, but not from the ‘banned‘ category:

<ItemGroup>
  <TestAssemblies Include="assemblies\test*.exe"/>
  <TestAssemblies Include="assemblies.lib\test*.exe"/>
</ItemGroup>

<Target Name="runTests">
  <Exec Command="$(teamcity_dotnet_nunitlauncher) v2.0 x86 NUnit-2.5.0 /category-include:test;lib /category-exclude:banned @(TestAssemblies)">
</Target>

To run NUnit with addins (for our example we chose the RowTest Addin), you need to specify the full path to the addin with the proper option of NUnit Launcher:

<ItemGroup>
  <TestAssemblies Include="assemblies\test*.exe"/>
  <TestAssemblies Include="assemblies.lib\test*.exe"/>
</ItemGroup>

<Target Name="runTests">
  <Exec Command="$(teamcity_dotnet_nunitlauncher) v2.0 x86 NUnit-2.5.0 /addin:RowTests.dll @(TestAssemblies)" />
</Target>

For afters we have the sample that shows how to run each test assembly in a separated test runner process:

<ItemGroup>
  <TestAssemblies Include="assemblies\test*.dll"/>
  <TestAssemblies Include="assemblies.lib\test*.dll"/>
</ItemGroup>

<Target Name="runTests">
  <Exec Command="$(teamcity_dotnet_nunitlauncher) v2.0 x86 NUnit-2.5.0 %(TestAssemblies)" />
</Target>

That would be all for today. We hope you’ve found something useful for you.

We wish you happy building!

Technorati tags: TeamCity, JetBrains, NUnit, NAnt, MSBuild, MS Visual Studio 2005, MS Visual Studio 2008, IntelliJ IDEA, Eclipse, continuous integration, build management, agile development

image description