Back to articles
1 min read

How to setup NCrunch with AutoFixture.NUnit2

Making AutoFixture.NUnit2 play nicely with NCrunch by relying on NUnit's built-in add-in discovery.

Gert Jansen van Rensburg

Gert Jansen van Rensburg

Software consultant

Now that AutoFixture.NUnit2 is out in the wild, a few people have commented that the deployment story has some friction. I agree-that’s how the NUnit extensibility model works. After a few attempts to make NCrunch work with AutoFixture I realised it was much simpler than expected: just follow the model.

AutoFixture.NUnit2 is an NUnit add-in. Let NUnit load it as an add-in. That is all.

Here is the approach I settled on:

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

namespace ...
{
    [NUnitAddin]
    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 as described in the NCrunch support documentation.

Why does this work? When you are developing NUnit add-ins, NUnit loads any class that implements IAddin into the test runner’s AddinRegistry. This behaviour is intended for development only, but we can piggyback on it.

Interesting side effects: you can use the built-in TeamCity NUnit runner with AutoFixture.NUnit2-no need for the MSBuild script I used previously.

Comments

Share your thoughts and join the discussion below.