Features FYI How-To's

.NET Code Coverage in Two Clicks

If you have ever dealt with .NET code coverage for NUnit tests, you surely know that it is quite a tricky thing to configure: you need to read docs to properly set up launching a command line coverage tool in your build script; read more docs and configure how reports should be gathered; then read docs again and specify all the needed arguments to be passed… well, not a task anyone would like to deal with.

Now imagine that you can forget all that tangled routine and spend more time doing whatever you like. That’s because starting with TeamCity 5.0 configuring coverage execution with NUnit becomes easy as pie.

All you need to do is to select the preferred coverage tool when creating or editing Build ConfigurationNCover and PartCover are at your disposal; and specify its parameters. That’s it!

Just a few clicks to make TeamCity automatically add necessary arguments to NUnit tests, and ensure you’ll be able to view the results in the TeamCity. Enjoy!

Code Coverage Results

Code Coverage Results

Code Coverage Summary

Code Coverage Summary

Coverage Graph

Coverage Graph

JetBrains TeamCity team.

Technorati tags: , , , , , , ,

Comments below can no longer be edited.

10 Responses to .NET Code Coverage in Two Clicks

  1. Avatar

    Romain Verdier says:

    February 19, 2010

    Very nice work, thanks.

    Too bad it’s not that easy to get coverage working with a different runner. For example, I didn’t figure out how to use Rake runner + PartCover in TeamCity.

    I’m using your nunitlauncher.exe from my rake file, by passing the specifics /partcover* switches, but then it seems pretty difficult to integrate the coverage results in TeamCity. I tried to use the importdata message without any success.

  2. Avatar

    jrummell says:

    February 19, 2010

    This sounds great! But I can’t get the sln2008 runner to work with PartCover. Any chance you’ll be updating the docs to include the .NET Coverage information (http://confluence.jetbrains.net/display/TCD5/sln2008)?

  3. Avatar

    t800t8 says:

    February 19, 2010

    Clicking is easy, but the main issue is to specify necessary parameters. Hope that the docs will be updated.

  4. Avatar

    Khalusova says:

    February 25, 2010

    2Romain Verdier: We are planning to support reporting .NET coverage from any runner via service messages in TeamCity 5.1. Don’t hesitate to vote for the corresponding issue http://youtrack.jetbrains.net/issue/TW-10918 .

  5. Avatar

    Philippe Leybaert says:

    March 1, 2010

    This simply doesn’t work, and it seems nobody else has got it to work either. At least not with PartCover.

    This feature really needs documentation, because I’ve yet to see a report from someone who gets the same nice code coverage statistics that you are showing in this blog post.

  6. Avatar

    Khalusova says:

    March 5, 2010

    The docs about configuring NCover and PartCover for NUnit are now updated.

  7. Avatar

    Dave M. says:

    March 22, 2010

    I haven’t been able to get NUnit working, either, though my current configuration is simpler (just trying to get NUnit working, not trying NCover yet). I get compilation errors, even though my solution builds fine in the IDE:

    Window1.xaml.cs(14,7): error CS0246: The type or namespace name ‘NUnit’ could not be found (are you missing a using directive or an assembly reference?) Window1.xaml.cs(28,10): error CS0246: The type or namespace name ‘Test’ could not be found (are you missing a using directive or an assembly reference?) Window1.xaml.cs(28,10): error CS0246: The type or namespace name ‘TestAttribute’ could not be found (are you missing a using directive or an assembly reference?)

    One difference is that I have the NUnit assemblies in a folder that is in SVN, because I need to build solutions on multiple computers that might not have the same version of NUnit, or have it in the same directory.

    I have also installed NUnit onto my test server, but the builds still fail with compilation errors. I also tried rebooting my machine after installing NUnit but that didn’t help.

  8. Avatar

    Eugene Petrenko says:

    March 22, 2010

    Dave, please check your Visual Studio project reference to NUnit uses hintPath to nunit.framework.dll that is checked out from subversion (but not to the one from GAC). Please either try running msbuild.exe solution.sln from the build agent under build agent service running user account.

  9. Avatar

    Dave M. says:

    March 22, 2010

    Thanks for the reply, Eugene! I checked my project file and it all looks good. The HintPath does reference my external libs folder from SVN. I also executed msbuild from the vs2008 command prompt and used /t:Rebuild to make sure I was rebuilding the solution. Everything checked out fine, but I still can’t get my build to work in TeamCity.

    Here is a link to my configuration screens: http://bit.ly/cy2KDM

  10. Avatar

    tim says:

    September 14, 2013

    Everything was working… until I added nuget package building, after that failed I disabled the step but it still fails, but now TeamCity cannot find the namespace for Moq and NUnit. VS on the same agent machine compiles it fine though.

Discover more