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

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.

Clone this wiki locally