How To Build an NUnit Addin
Since version 2.2.x of NUnit it was possible to build your own core extensions, but this feature was experimental. With the latest release Addins are officially supported. Core extensions can customize NUnit's internal behavior such as the creation of tests and their execution.
Writing an Addin
An Addin needs to implement the interface
NUnit.Core.Extensibility.IAddin, which can be found in the
assembly “nunit.core.interfaces”. Additionally the
NUnit.Core.Extensibility.NUnitAddinAttribute must be applied to
your Addin class. The attribute parameters Name and Description
represent the name of the extension and a description of what it
does. You can leave ExtensionType at its default value
(ExtensionType.Core), because NUnit supports only core extensions
by now. The interface NUnit.Core.Extensibility.IAddin has only
one method which is called Install. Your Addin class will install
extensions at certain extension points, places where the NUnit
functionality can be extended. To locate such extension points your
Addin class uses the extension host, which is passed as parameter.
The Install method returns true when your Addin was able to
install your extensions, otherwise it returns false. A minimal
Addin would look like this:
using System; using NUnit.Core.Extensions; [NUnitAddin(Name=”MyAddin”, Description=”This Addin does not do anything.”)] public class MyAddin : IAddin { public bool Install(IExtensionHost host) { return true; } }
How to Install an Addin
After compiling the Addin copy the assembly to the bin/addins
directory relative to the NUnit install directory. Start the NUnit
GUI and you should see your Addin listed under Tools -> Addins...:
MyAddin does not do anything useful. The next time I'll show you
how to write a test decorator.
