10.6 Analyzing Unit-Test Coverage with NCover

Unit tests are critical to producing solid, professional software, but how do you know whether you’re hitting the key areas of your software with your tests? Complex algorithms might have odd corners, and unique conditions might be required to exercise those paths. Can you be sure your unit tests are setting up conditions properly to travel through all branches?

NCover is a code-coverage tool that was designed to help developers answer that question. Code-coverage tools monitor a program during execution and report how much of the code was executed.

Most code-coverage tools add extra instrumentation code to your project’s source-code files in order to capture this information. NCover is unique in that it requires only the .pdb debug files generated by the .NET compilers in order to get code-coverage data. This means that you can run NCover on your production code without modifying it. NCover dynamically generates the IL needed to collect coverage data at runtime and injects this code into the running program.

Also, since NCover operates at the CLR level, it is language-agnostic. NCover has been used successfully with C#, VB, and C++ (compiled with the CLR option). Any code that runs on the CLR should work with NCover, as long as the compiler generates compatible .pdb files (all the Microsoft compilers do). As of this writing, NCover supports all versions of the CLR (1.0, 1.1, and 2.0).

NCover at a Glance

Tool

NCover

Version covered

1.5.4

Home ...

Get Windows Developer Power Tools now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.