Skip to content

What do the coverage values mean?

irongut edited this page Nov 15, 2021 · 16 revisions

Code Coverage Summary provides a useful set of statistics to help you improve the quality of your code but what do the values actually mean?

image

Line Rate

Branch Rate

Branch Rate is a metric that indicates whether all branches in a codebase are exercised by tests. A branch is one of the possible execution paths the code can take after a decision statement — e.g. an if statement — gets evaluated.

Branch Rate is an important metric that can help a team or organization assess whether an application has been tested to completion. A low branch rate shows that there are scenarios in the application lacking testing. Such scenarios might contain defects that will only manifest in edge cases when the application makes it to production.

Complexity

Cyclomatic complexity measures the number of possible paths execution could take through a given method or function. Simple functions that have no branching will have a complexity of 1. A complex method with many different if clauses and / or switch statements will have a much higher complexity score. A general guideline for the complexity of a function or method is that it should be kept under 10 whenever possible and that anything over 30 is probably not maintainable. When analyzing code to look for problem areas, identifying the highest complexity values is often a good place to start.

When analyzing classes with auto-properties, or just many small methods, you'll frequently see many complexity values of 1 because each get and set method will have a complexity value of 1. This makes it difficult to use cyclomatic complexity as a heuristic or benchmark for classes, namespaces, or projects / assemblies. Cyclomatic complexity is only really useful as a method or function measure, it breaks down at class and higher levels.

The Summary complexity value is the sum of the individual package values.

Clone this wiki locally