Cyclomatic Complexity

Table of Contents

Cyclomatic complexity represents the number of linearly independent paths through a program’s source code (i.e. the minimum ideal number of tests each testing a path).

There are two ways to calculate the cyclomatic complexity :

  1. Option 1: based on the control flow graph of the program : Complexity = E – N + 2 (where E = number of edges and N = number of nodes).
  2. Option 2: based on the number of decision points contained in that program plus one: Complexity = P + 1 (where P = number of decision points).

Cyclomatic Complexity

​BluInsights implementation relies on Option 2 and is available for multiple languages. The cyclomatic complexity of any structured program with only one entry point and one exit point is equal to the number of decision points contained in that program plus one. The decision points are ifforfor-eachwhiledocatch, and case statements. For each method in a program, we calculate this cyclomatic complexity, and the sum of the cyclomatic complexity of each method of a file gives the total cyclomatic complexity of the file. Each language has only certain types of files containing code (i.e if a file doesn’t contain code such as Images, its complexity will be 0.

 

Launch 

On the Statistics tab of the Assets module, click on the “…” button on the upper right corner of the screen and select “Launch” in the complexity section. Pick up the technologies related to your codebase and hit the Launch button.

Launch Cyclomatic Complexity

Results

When the metrics are available, the Cyclomatic Complexity column can be displayed on multiple pages such as Assets, Workpackages, and Test Scenarios. On each page, the values are consolidated at different levels.

  • Assets: values are related to files.
  • Workpackages: values are related to files and workpackages (sum of the complexity of its files).
  • Test Scenarios: values of the related workpackages.

Cyclomatic Complexity Column

Different charts can also be added to the dashboards:

  • Cyclomatic Complexity Per Lines of Code. It shows the number of Lines of Code as the x-axis and the Total Cyclomatic Complexity as the y-axis, each dot corresponding to a file.

Cyclomatic Complexity per Lines of Code

  • Cyclomatic Complexity Per Workpackages. It displays the cyclomatic complexity per workpackage.

Cyclomatic Complexity per Workpackages

  • Cyclomatic Complexity Per Test Scenarios. It displays the cyclomatic complexity per test scenario.

Cyclomatic Complexity per Test Scenarios