views:

350

answers:

4

I'm looking for a tool (preferably free) that analyzes incremental code coverage of our C# solution. What I mean by this is that I don't want to know what the total code coverage is for all code or even for a namespace, but only new lines of code or perhaps lines of code that changed since the last checkin. (We use subversion for source control.)

I would like to call this tool as part of our automated build process and report back when someone checks in new code with less than X% code coverage.

Does anyone know of a tool that accomplishes this?

Thanks.

+3  A: 

NDepend boasts the following:

NDepend gathers code coverage data from NCover™ and Visual Studio Team System™. From this data, NDepend infers some metrics on methods, types, namespaces and assemblies : PercentageCoverage, NbLinesOfCodeCovered, NbLinesOfCodeNotCovered and BranchCoverage (from NCover only).

These metrics can be used conjointly with others NDepend features. For example you can know what code have been added or refactored since the last release and is not thoroughly covered by tests. You can write a CQL constraint to continuously check that a set of classes is 100% covered. You can list which complex methods need more tests.

I seem to recall NDepend being able to compare with data from earlier builds, so it looks like the combination of NDepend and NCover might do the trick. Haven't tried it myself though. .)

Rytmis
A: 

Depending on the version of .Net you can use NCover for free. However if you are on the newer versions of .net it's not so cheap. You would probably still have to write your own stylesheet to parse the results of NCover to get specifically what you are asking.

Other than that I have not heard or seen of another tool to do this unless you wanted to write it yourself.

NCover basically uses the .Net Profiling API so in theory you could just do the same.

Joshua Cauble
Partcover (http://sourceforge.net/projects/partcover/) is free, works for the latest runtime versions and outputs the same data as NCover. The OP would still need to mine this data for 'new code' with low coverage.
Hamish Smith
Awesome I'll have to take a look at that project. We actually have nCover at work but it would be nice to have something similar at home.
Joshua Cauble
A: 

I use PartCover to analyse my unit tests for good effect. For the data you're looking for, you can use the console tool and extract the visit and len counts from the report xml.

David Schmitt
A: 

In addition to the Rythmis answer, I provide this blog post that explains in detail how NDepend coupled with NCover or VSTS coverage answers the question: Are you sure added and refactored code is covered by tests?

Patrick Smacchia - NDepend dev