Please visit Coverage Metrics for updated information.
NCover gathers and reports on four different types of code coverage or code metrics. Each affords a different insight into the code you've tested, and each helps you understand the code better. This article explains and illustrates the four coverage metrics that NCover supports, and provides some suggestions on using them effectively.
Symbol Coverage
Symbol coverage measures how many sequence points have been executed. A sequence point is the thing that Visual Studio highlights when you step through code in the debugger. Sequence points are always small enough to be either completely executed or not completely executed, so they avoid the 'partially executed' problem that method coverage has.
Symbol coverage gives a very detailed and granular view of which code has been executed and which code has not. There can often be multiple sequence points per line, for example in a for statement or a ternary expression. Sequence points can also be nested within each other or overlap, or span multiple lines, as stepping into a moderately complex lambda expression will reveal. The major failing of symbol coverage is that without examining the code it's impossible to tell whether conditional statements (such as if statements) have executed both their 'true' and their 'false' blocks.
Method Coverage
Only available in the Complete edition
Method or function coverage measures how many methods have been executed. The method could exit partway through, or it could throw a NotImplementedException as soon as it's called, but it will still count as executed for this metric. Method coverage of 50%, for example, means that half of the methods under the module, namespace or class have been called, and half have not been called.
Method coverage gives a very high level overview of how well a project is covered. Because the metric only tells you whether a method was called, low coverage is really, really bad, and high coverage isn't very assuring. 90% method coverage is good minimum goal to set, but you should be able to get 100% coverage without too much work.
Branch Coverage
Only available in the Complete edition
Branch coverage measures the number of executed basic blocks in the control flow graphs of all methods. Essentially, each method is analyzed and broken into sections that have a linear execution by starting new sections at the start and end of every conditional statement (such as an if or a switch statement), at statements that could exit a method, and around try-catch-finally blocks. Each section (basic block) is executed once the last statement in it has been executed.
Branch coverage is a slightly higher view of code coverage than symbol coverage, since a block usually contains several sequence points. However, branch coverage also provides greater detail than symbol coverage because it differentiates between if statements that evaluated 'true' and if statements that evaluated 'false', only counting if statements that evaluated to both 'true' and 'false' as completely executed.
Cyclomatic Complexity
Only available in the Complete edition
Cyclomatic complexity is a measure of the inherent complexity of a method. A method's complexity is measured by the number of linearly independent paths from the start of the method to an exit point. The number of linearly independent paths through a method is generally smaller than the total number of paths, although every possible path can be formed by combining several linearly independent paths.
In general, the more complex a method is, the harder it is to test or maintain, and the more likely it is to contain bugs or implementation errors. The cyclomatic complexity value is the maximum number of test cases needed to get 100% branch coverage, and the minimum number of test cases needed to exercise every path through a method, so it provides a good way to tell how well-tested a method is. Generally, methods with a cyclomatic complexity of 15 or higher are too complex, and should be refactored if possible (note that methods with switch statements usually have a higher-than-normal cyclomatic complexity).
Recommended Reading
To learn more about generating reports based on these coverage statistics, see our article on creating reports.
To enable the recording of different coverage types, see the NCover Console //ct flag.
To learn more about Cyclomatic Complexity, please read this.