- Create your NUnit Test project as a Windows Console Application, not as a Class Library.
- Then make your main Program look like this:
[csharp]
[TestFixture]
public class Program
{
static void Main(string[] args)
{
NUnit.ConsoleRunner.Runner.Main(
new[]{Assembly.GetExecutingAssembly().Location }
);
}[TestCase("Aa - Bb")]
public void WhenValidatingForename_should_accept_valid_characters(string validInput)
{
var result= new ClassUnderTest().Validate(validInput);
Assert.IsTrue(result);
}[TestCase("X<")]
public void WhenValidatingForename_should_reject_invalid_characters(string invalidInput)
{
var result= new ClassUnderTest().Validate(invalidInput);
Assert.IsFalse(result);
}
}[/csharp] - Then, add a reference not only to
nunit.framework.dllbut also tonunit-console-runner.dll
You now have a self-running executable that runs all your tests, but still behaves in the usual way in a build script, or when running tests inside Visual Studio with TestRunner or Resharper or similar.
NB You may need to check if your build scripts are hard-coded to expect a Test project to be a .dll.