Friday, January 25, 2008

Code Coverage with TeamCity

In my previous post on JetBrains TeamCity I mentioned that it has no support for .NET code coverage.  With this post I want to correct the injustice of this statement. It was a simple case of RTFM that solved this issue. Actually this great post pushed me into the right direction (you can even download some specific TeamCity MsBuild tasks).

One might think you have to jump through quite some hoops in order to integrate code coverage, but it is actually really easy. Here goes:

1. Make sure that your build script creates a code coverage report. I'm using NCover/NCoverExplorer for this with the corresponding MsBuild tasks that you can download here (in the NCoverExplorer Extras package).

2. Add the code coverage results file to the artifacts:TeamCityArtifacts

3. Add the following line to the TeamCity Data Directory/config/ main-config.xml file as described here:

<report-tab title="CodeCoverage" basePath="" startPage="CodeCoverage.html"/>

4. You're done.

Now behold the results:

TeamCityCodeCoverage

It creates a new tab for the build results that integrates the code coverage artifact. The coolness of TeamCity just keeps amazing me.

7 comments:

DeeJay said...

I just got started using TeamCity and love it! However, I now want to add the ability to run NCover on my build but can't seem to get the MSBuild file correct. Can you post or email an example so I can see what I've done wrong?

Jan Van Ryswyck said...

I've provided a sample here.

Slava Imeshev said...

You might want to check out our Parabuild that is a build and release management system. It gathers and displays coverage reports as well, but it is a bit easier to use. In Parabuild all configuration is done through a neat Web user interface, so you don't have to add or edit XML files.

frankhermez said...

Unfortunatelly you don't have free license for Parabuild (only evaluation). That's the one reason why we even didn't give a try to Parabuild.

Cygon said...
This comment has been removed by the author.
Cygon said...

@Slava: From your comment, I get the feeling you never even looked at TeamCity.

I think saying Parabuild is easier to use - even just "a bit" - is quite... far fetched. Imho, TeamCity's web interface is both easier to use and visually more appealing. TeamCity allows all configuration to be done via the web interface as well (maybe you're mixing it up with CruiseControl?).

The only difference is that TeamCity, unlike Parabuild, doesn't support NCover out of the box (as of TeamCity 3.0). This article explains how to integrate NCover into TeamCity. And since NCover is now commercial, you can use the same approach to integrate its free alternative PartCover into TeamCity within 5 minutes! Try that with Parabuild :)

Kunal said...

Hey,



Thanks for your valuable comment, I am using rake runner type in my project.

Is the same way it will work for Rake type? I am able to add custom report tab, but it is not displaying. Please help on the same.


Thanks and regards,
Kunal Ghosh