Devlico.Us
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @devlicious

Casey Charlton - Insane World

Hang the code, and hang the rules. They're more like guidelines anyway


Statistics and How They Lie

Industry experience suggests that the design of metrics will encourage certain kinds of behaviour from the people being measured. The common phrase applied is "you get what you measure" (or "be careful what you wish for").

A Brief Explanation of Cyclomatic Complexity and Code Coverage

Cyclomatic complexity is a measure of the number of possible paths through a piece of code. This is a relatively easy measurement to make, and code analysis tools can give you this figure directly. As cyclomatic complexity is directly analogous to the number of paths through the code, it is also a direct count of the number of unit tests required as a minimum to test all the code paths.

  • A cyclomatic complexity of 1-10 is a simple piece of code that is easily maintainable.
  • A cyclomatic complexity of 11-20 is a moderately complex piece of code, that is relatively easy to maintain.
  • A cyclomatic complexity of 21-50 would indicate either a highly complex or high risk piece of code. The functionality of the code observed indicates it is in no way complex, and therefore it must fall into the high risk category.
  • A cyclomatic complexity of 51 and above indicates un-testable code, and a very high risk to the project.

Code coverage measures the number of paths through your code that had at least one execution when unit tests were run. It does not however give any real quality measure against the value of those tests, or the actual quality of those tests.

It is actually easier to get better coverage results from writing poor code. The poorer the quality of your code and of your tests, the easier it is to achieve high coverage figures.

See also: Measuring Progress



Comments

Davy Brion said:

Yeah, code coverage is such a terrible indicator... the only time it really means something is when it's low... at least you can be sure that's not good.  If it's high, it doesn't mean anything.  

I also love when people generate tests to increase their code coverage... that's like a double WTF ;)

# May 16, 2008 8:04 AM

Bill Miller said:

Why is it a negative to know something about the coverage of your test suite?  While knowing that alone isn't everything, knowing something about it is knowledge useful for improving the quality of your testing.  

# June 2, 2008 7:56 PM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add

About Casey Charlton

A somewhat passionate and opinionated developer, with occassional sparks of wisdom, and occasional useful information. Check out Devlicio.us!

Our Sponsors

Red-Gate!