Ensuring software quality requires much more than testing and should start much earlier in the development lifecycle. One activity that can help is cyclomatic complexity analysis. For cyclomatic complexity analysis, simply put, higher numbers indicate more complexity and are “bad” while lower numbers are “good”. Some modules and their functions may be inherently more complex to implement and therefore have a relatively high cyclomatic complexity than other modules. Cyclomatic complexity gives us a sense of how hard code may be to test, and maintain thereby also indicating proneness to errors. Naturally, the goal should be to minimize complexity while still achieving the functionality required. So if we can determine the cyclomatic complexity of the code, it can help us with our test strategy in putting our efforts in those areas and functions that are more likely to have problems. Studies have shown that the 80/20 or even 90/10 rule applies to software code as well, meaning that 80-90 percent of the errors are within 10-20 percent of the code. So the goal in testing should be to identify those modules ahead of time and target test cases and effort toward those error prone or naturally high CC modules. There are many tools that can help you with examining your cyclomatic complexity.

  1. source monitor
  2. ndepend
  3. code metrics
  4. refactoring

These are just a few tools that you can use for cyclomatic complexity analysis. Which tools are you using? Do you find them helpful?