March 11, 2010

Code Coverage analysis for .NET projects in TeamCity 5

I personally don't use test code coverage as a goal in itself, but it is a great tool to find the blind spots - finding classes and methods that don't have coverage, but really should.
Speaking in numbers, I don't set a certain code coverage percentage as a strict required minimum, instead I look for classes or namespaces that falls below a certain treshold, like 60%.

My favorite build server of choice now makes it easier to keep track of the code test coverage. Team City Version 5.0+ has a nice little new part (Build Configuration –> Runner) :

Out of the box TeamCity supports NCover (commercial and community versions) and PartCover.  Let’s look at NCover – there is a free (however old) community edition. NCover provides much more progressed commercial versions if you want to do advanced coverage analysis and Visual Studio integration, but let’s start small with the community edition.

On the build server:
Download and install NCover Community 1.5.8 (you need to register, which is free).
Download and install NCover Explorer (this is just a zip, unzip it to an “Explorer” sub folder to the NCover install location).
Now you just need to set it up from the TeamCity Build Configuration –> Runner page:

A few things to note:
Don’t count on the autodetection of the NCover install files, especially if you are on a 64-bit server. Put those paths in manually.
Enter the assemblies to analyze – without extension, and one on each line.

Now you are ready to go. Run a build and check out the code coverage report:

You can choose between different reports to view assemblies, namespaces, methods and classes to find potential blind spots. I find this a valuable extension to your build server that it is hard to be without, once you have started using it.

No comments:

Post a Comment