Category Archives: TeamCity

Howto get AutoFixture.NUnit2 working with NCrunch

Now that the AutoFixture.NUnit2 is out there in the wild, a few people have commented that the deployment story has a bit of friction, and I agree with that statement, but that is how the NUnit Extensibility model works.

After a few attempts to make NCrunch work with AutoFixture.NUnit2 resorted to looking on NCrunch support forum it mentioned to include the Addin in the test assembly. This got me thinking… what if we created a class inherited from AutoFixture.NUnit2 Addin. To my surprise this worked.

Here is how:

  • 1. Install-Package AutoFixture.NUnit2
  • 2. Install-Package NUnit.Runners (will have to manually reference tools\nunit.core.interfaces)
  • 3. Remove this line [assembly: NUnit.Framework.RequiredAddin(Ploeh.AutoFixture.NUnit2.Addins.Constants.AutoDataExtension)] from AssemblyInfo.cs
  • 4. Create the below class in each test assembly
using NUnit.Core.Extensibility;

namespace ...
    public class LocalAddin : Ploeh.AutoFixture.NUnit2.Addins.Addin

To make NCrunch work with AutoFixture.NUnit2 change the “solution configuration” – “framework utilisation type for NUnit” option from “Dynamic Analysis” to “Static Analysis” this is explained in the support documentation

Why does this work?
When you are developing NUnit Addins, NUnit will load any classes that implements IAddin into the test runner’s AddinRegistry this is intended for development only.

Interesting side effects
You can use the buildin TeamCity NUnit Runner with AutoFixture.NUnit2 no need to use msbuild script as previously explained.


Howto setup TeamCity NUnit Runner with AutoFixture.NUnit2

In a previous post I explained how setup AutoFixture.NUnit2 to work with a few 3rd party applications, to complete the AutoFixture.NUnit2 story we need to be able to configure TeamCity for Continuous integration according to Teamcity documentations there are a few ways to do this, but only way I have been successful so far was to configure msbuild script to run nunit-console.exe

Example of msbuild script to copy Teamcity NUnit Addin and AutoFixture.NUnit2.Addins.dll

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="" DefaultTargets="CompleteBuild" ToolsVersion="4.0">

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

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

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