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 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" />

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?


At November 15, 2006 10:59 AM, Blogger Fanlan said...

Thanks a lot Grant.

At November 18, 2006 10:26 AM, Anonymous Eden said...

Another approach is to use ILMerge to create a single test assembly. It will obviously be a bit slower.

Great work Grant.

At July 23, 2007 12:34 PM, Anonymous neni said...

I get a coverage.log file produced, but no coverage.xml file. Any ideas?

At July 24, 2007 9:28 PM, Blogger kiwidude said...


I suggest you take a look at my two postings on ncover problems/fixes recently on my blog - the most likely cause is coverlib.dll not being registered


Post a Comment

Links to this post:

Create a Link

<< Home