Hornet Dear Bernard

Dear, Dear Bernard

In pursuit of code quality: Monitoring cyclomatic complexity

leave a comment »

In pursuit of code quality: Monitoring cyclomatic complexity.

Some interesting snippets:

…What’s interesting here is that we were able to spot this defect using cyclomatic complexity rather than code coverage. Code coverage indicated we were done after one test case, but CC forced us to write an additional one. Not bad, eh?

Luckily, the method under test in this case only had a CC of 2. Imagine if that defect were buried in a method with a CC of 102. Good luck finding it!

…As demonstrated above, cyclomatic complexity is a good indicator of code complexity; moreover, it’s an excellent barometer for developer testing. A good rule of thumb is to create a number of test cases equal to the cyclomatic complexity value of the code being tested. In the case of the updatePCensus() method seen in Figure 2, you would need 114 test cases to achieve full coverage.

Advertisements

Written by bernardhornet

April 21, 2011 at 7:31 am

Posted in Uncategorized

Tagged with , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: