Hudson NAnt NUnit

Jun 25, 2012
Oshyn Labs

This post basically is a continuation of the post “Hudson Parameterized Builds with NAnt”. I am going to talk about how to integrate NUnit on Hudson builds. NUnit is a unit-testing .NET framework that is used to write and run tests cases, and is written in C#.

The integration between Hudson and NUnit is based on NAnt technology. The reason of that is because the main functionality of NUnit testing is implemented in the NAnt script called by Hudson. The following software must be installed on the Hudson machine:

•   NAnt, http://nant.sourceforge.net/
•   NantContrib, http://nantcontrib.sourceforge.net/
•   Framework 3.5 and VS 2008 with test library

If you want to do this NUnit integration,  you need to include in your NAnt script the following code:

<nunit2 failonerror="${failonerrortest}">
    <formatter type="Plain"/>
    <test assemblyname="TestProject.dll" appconfig="TestProject.dll.config" />
</nunit2>

1.   The parameter ${failonerrortest} can have the values true|flase where true means that the Hudson build is going to fail if at least one test fails.

2.   The attribute assemblyname is the path or location of the dll that contains the test cases project.

3.   The attribute appconfig is the config file that is going to be used in order to run the test cases.
There is another way to run tests individually instead of run all the entire test project. If you want to do that, you just need to use the attribute “testname” for the tag “test” with the name of a specific testfixture to run.

Suppose that your NAnt script build has the following code:

<msbuild project="${Solution.Filename}">
    <property name="Configuration" value="Release"/>
</msbuild>

Where ${Solution.Filename} is the parameter sent from Hudson that means the solution that is going to be compiled. In order to generate the files TestProject.dll and TestProject.dll.config, your test project needs to be included into the solution or the Test project is not going to be compiled and the dll is not going to be generated.

On this post I just talk about NUnit testing with NAnt, but if you need more information from the integration between Hudson and NAnt, please check the post “Hudson Parameterized Builds with NAnt”.