views:

29

answers:

1

I am using Visual Studio 2008 Code Coverage and I have many classes that are 100% covered by my unit tests. How could I check during my build process that these classes remain 100% covered by my unit tests (also executed during my build process after compilation) ?

A: 

For code coverage ratio check you can use NDepend. You can declare an attribute, like YourNamespace.FullCoveredAttribute and tag your classes 100% covered by tests.

using YourNamespace;
...
[FullCoveredAttribute]
class MyClassFullCovered { ... }

Then the single following CQL query will check for all classes 100% covered and warn if it finds any flaw:

WARN IF Count > 0 IN SELECT TYPES WHERE
HasAttribute "YourNamespace.FullCoveredAttribute" AND
PercentageCoverage < 100

The magic comes from the fact that NDepend can gather code coverage metric from both NCover and VSTS Coverage.

Patrick Smacchia - NDepend dev