How to view Cyclomatic Complexity in Visual Studio

Cyclomatic complexity is a measure of the distinct paths in a method. It can be useful for getting an idea how complex a method is.

In general a method with a cyclomatic complexity of 2 is said to be less complex than a method with cyclomatic complexity of 20 etc.. so lower numbers are ‘better’. In terms of our automated testing, if our method under test has a cyclomatic complexity of 5 we should have AT LEAST 5 tests against this method.

It’s easy to get the cyclomatic complexity of our code in Visual Studio. It’s available from the Analyze -> Calculator Code Metrics menu option…

… and an example of Visual Studios cyclomatic complexity results is below…

Leave a Reply

Your email address will not be published. Required fields are marked *