Wednesday, March 23, 2011

How to prevent NUnit from running some tests on the build server

Certain NUnit tests you only want to run on your local machine and some you only want to run on the build server. To make this easy NUnit offers the "Category" attribute.
[Test][Category("DoNotRunOnBuildServer")]
public void ReadFromLocalWebServiceTest()
{
    var qdbBrandHttpReader = new QdbBrandHttpReader();
    string xml = qdbBrandHttpReader.ReadFromLocalWebService();
    ...
}
On your build server, when you invoke NUnit console add the option "/exclude:DoNotRunOnBuildServer", then it will not even try to run these tests.
Typically this is used with a category like "LongRunningTests" to prevent tests from running on your local box.

No comments: