Wednesday, November 15, 2006

Creating NUnit Projects Dynamically

I referred in my Merging NCover Reports blog entry to a NAnt task I created a long while ago to resolve the issue of running multiple unit test assemblies in a single coverage run while using NUnit. By creating a .nunit project on the fly based on a wildcard pattern for test assemblies we avoid the hassles of manually maintaining it as the solution projects grow. For TestDriven.Net addicts who rarely run the NUnit GUI like myself this gives the best of both worlds.

Since a couple of people asked me to make it available I have now added both this and an MSBuild version to the respective NCoverExplorer.NAntTasks.dll and NCoverExplorer.MSBuildTasks.dll assemblies.

Download the latest NCoverExplorer.Extras.zip file to get the compiled assemblies, source code and documentation with examples. For a quick and dirty preview, the NAnt task looks something like this:

<nunitproject project="${outputdir}\MyApp.nunit" appConfig="${outputdir}\MyApp.exe.config">
     <fileset basedir="${outputdir}">
         <include name="MyApp.*.Tests.dll" />
     </fileset>
</nunitproject>

You can now change your NAnt task executing NUnit so that it is passed the name of the .nunit project file rather than the testing assembly inside some loop. This will give you a single xml file summarising the test runs. If you similarly do the same for running NCover you get a single coverage.xml file for your project.

I should add that this has only been used with the NUnit 2.2.x project versions - having not had a chance to look at the NUnit 2.4 betas myself as yet perhaps someone can let me know if they significantly changed the .nunit project file format?