Back to articles
1 min read

How to setup TeamCity NUnit Runner with AutoFixture.NUnit2

Using MSBuild to copy AutoFixture add-ins so TeamCity's NUnit runner can execute tests.

Gert Jansen van Rensburg

Gert Jansen van Rensburg

Software consultant

In a previous post I explained how to set up AutoFixture.NUnit2 to work with a few third-party applications. To complete the story we need to configure TeamCity for continuous integration. According to the TeamCity documentation there are several options, but the only approach I have used successfully is running nunit-console.exe via an MSBuild script.

Below is the MSBuild target I used to copy the TeamCity NUnit add-in and AutoFixture.NUnit2.Addins.dll into place before running the tests:

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="CompleteBuild" ToolsVersion="4.0">
    <PropertyGroup>
        <NUnitHome>packages\nunit.runners.2.6.2\tools</NUnitHome>
    </PropertyGroup>

    <ItemGroup>
        <NUnitAddinFiles Include="$(teamcity_dotnet_nunitaddin)-2.6.2.*" />
        <NUnitAddinFiles Include="packages\AutoFixture.NUnit2.3.9.0\lib\net40\Ploeh.AutoFixture.NUnit2.Addins.dll" />
    </ItemGroup>

    <Target Name="RunTests">
        <MakeDir Directories="$(NUnitHome)\addins" />
        <Copy SourceFiles="@(NUnitAddinFiles)" DestinationFolder="$(NUnitHome)\addins" />
        <Exec Command="$(NUnitHome)\nunit-console.exe $(TestAssembly)" />
    </Target>

    <Target Name="CompleteBuild" DependsOnTargets="RunTests" />
</Project>

Comments

Share your thoughts and join the discussion below.