Skip to main content
GlossaryMetrics & ReportingCyclomatic Complexity

Cyclomatic Complexity

Cyclomatic complexity is a metric that counts the number of independent linear paths through a piece of code, based on its conditional branches — a higher number means more possible execution paths, and generally more test cases needed to achieve meaningful branch coverage of that code.

Calculated from a function's control flow graph, cyclomatic complexity roughly equals the number of decision points (if statements, loops, case branches) plus one — a function with no conditionals has a complexity of 1 (one path); each added conditional roughly adds one more possible path to consider.

For testing specifically, cyclomatic complexity is a useful heuristic for where to focus effort: a function with high complexity has combinatorially more paths that could each hide a distinct bug, and achieving genuine branch coverage of it requires proportionally more test cases than a simple, low-complexity function needs.

Cyclomatic Complexity — Definition, Example & How It's Used | QA Bash Glossary | QA Bash