Thursday, October 12, 2006

NCoverExplorer... Merging NCover Reports

There have been a couple of posts recently by Jeremy Miller and debating how best to structure unit test code. One of the arguments mentioned by a number of people against multiple unit test assemblies is the difficulty of merging multiple NCover coverage files on the build server.

To the people who posted comments along the lines of "it's just not possible"... well in actual fact it is, and here are a couple of ways to do it.

The first option for NUnit users is to use a .nunit project file listing your test assemblies. This requires only a single execution of NUnit and means that only one coverage file is produced in the first place, avoiding the problem altogether. I have a custom NAnt task that I wrote for dynamically creating the .nunit project file based on a file pattern just to avoid any maintenance - if anyone else is interested let me know and I will make it available.

The second option is to use NCoverExplorer. The console executable version is designed to be used on the build server. Included amongst it's abilities since v1.3.4 is the ability to merge raw NCover coverage files and save the result along with xml/html reports if required. In addition you can optionally apply coverage exclusions etc at the same time.

This can be run either directly from the command line or using the NAnt/MSBuild tasks available in the NCoverExplorer.Extras zip file.

So... to merge a bunch of suitably named coverage.xml files from a test coverage run into a single file using the command line it can be as simple as:

ncoverexplorer.console.exe *.coverage.xml /s:merged.coverage.xml

If you want to produce an actual report instead, just add the /r argument indicating the report type, and any combination of /x or /h to produce xml or html output as appropriate. Of course the xml output is designed to be merged into your CC.Net build file and transformed using the CC.Net stylesheets also in that Extras zip file. Use /? to see the full command line options.

The same operations can also be performed using the NAnt or MSBuild tasks, documentation for which is found here for NAnt and here for MSBuild.

[Update Nov 14th 2006: I have made available the NAnt and MSBuild tasks to dynamically create nunit project files as detailed here.]


At October 25, 2006 10:25 AM, Anonymous Juanjo said...

Hi Kiwidude, i will really appreciate if you make accesible this NAnt task as i am working with more then one dll for testing and i want to run ncover on it.
Thank you!!!

At November 14, 2006 7:42 AM, Blogger Fanlan said...

Hi Grant,

I would appreciate it if you would make the NAnt task for generating an nunit project file available.

Thanks for all the work you've done in the community. You help make our jobs easier!

At November 15, 2006 12:42 AM, Blogger kiwidude said...

Hi guys - you can now find the tasks available as posted about here:

Let me know if you find any issues.

At March 09, 2007 1:51 PM, Blogger Carel said...


Thanks for the Tasks. I ran into an issue using the NCover task in collaboration with our mocking framework TypeMock. TypeMock needs to itself link in with NCover and provides a MSBuild task to do this. However, as you automatically link NCover yourself this resulted in coverage not working. I downloaded the source and removed the 2 calls to link and unlink NCover. When I did this everything worked smoothly again.

Can I suggest that you add an additional property to the NCover task by which you can set whether you want to automatically link or not. The default value can be true so this won't break any existing users. I can then set it to false to accommodate our mocking framework.


At March 09, 2007 8:04 PM, Blogger kiwidude said...

Hi Carel,

Sorry you have lost me a bit with the term "linking" - not using TypeMock myself I'm not sure which code is causing you the problem. Did you mean the registering/unregistering of coverlib.dll in the registry? If so I have had another request for the same thing and certainly parameterising it sounds a better idea for the next release. If you meant something elase please let me know some details on those offending lines...

At March 10, 2007 7:45 AM, Blogger Carel said...


100% right - I'm talking about the registering/unregistering of CoverLib. TypeMock needs to register itself and because the NCover task also registers, the tools don't work together.

Thanks for the excellent work you've done on NCoverExplorer.


Post a Comment

Links to this post:

Create a Link

<< Home