Getting NCover to work with nant builds was more messy than I assumed. What’s more appalling about all this is that programmers new to NCover download it from the default NCover landing page, only to find that its a paid version(3)(version 1.5 is sufficient for most use cases and serves most of the purposes.)
Another concern was that most of the the ncover tutorials on the web showed how to test a single unit test assembly even though ncover comes with a nunitproject nant task to pick out multiple test files(which is the highway case).
Without much further ado, here’s what I did
NCover Extras encapsulates the functionalities provided by NCover as a set of nant tasks. This needs to be loaded.Also CoverLib.dll that comes with NCover needs to be registered.
Add these lines before the target is called.
Now for the actual task…
The node with the nunitproject picks all the test dll’s from the output directory and builds a tests.nunit project file. This will be the input to Nunit which NCover will profile.
Digging into the NCover node you’ll see how NCover is being instructed to take pick the assemblies. If you are copying the code verbatim then change the assemblies node to pick your project dll’s and avoid test dll’s(By convention test assemblies are named ProjectName.Tests.dll). The output of this profiling task will be an xml file(Unit.Test.Coverage.xml in this case) which will be the input to NCoverExplorer, to get those fancy html outputs.
Here’s a typical NCover output xml..
The next node ncoverexplorer takes the xml files and builds a html output. Something similar to what’s shown below. Additionally the attribute failMinimum(not shown in this case) will fail the build if coverage doesn’t meet the coverage percentage specified.
Here’s a sample output.
One little quirk I encountered here was using nunit-console.exe instead of nunit-console-x86.exe. My 64 bit Server 2008 build machine rejected the first executable outright since it ran as 64 bit.
What pissed me of in this exercise was the time it took to integrate a seemingly simple open source project. Pretty much the same experience I had dealing with DD-WRT firmware sources. Once the author/company decides to to release a higher version of the project as a paid version or to make money out of the project, they then obfuscate source paths or put in obstacles that deter consumers from downloading those open source versions.
In case of the DD-WRT the source was hidden inside GB’s of data and in this case the official NCover website removed all the forums and added nag screens asking users to signup(given below) before downloading..