Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
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


Posted 05-16-2008 10:49 AM by Jak Charlton

[Advertisement]

Comments

Davy Brion wrote re: Statistics and How They Lie
on 05-16-2008 8:04 AM

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 ;)

Bill Miller wrote re: Statistics and How They Lie
on 06-02-2008 7:56 PM

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.  

Tim Barcz wrote Code Coverage - 100% Coverage and Still Failing
on 03-31-2009 1:18 PM

Casey posted last year about statistics that lie . In the post Casey gives an overview of Cyclomatic

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Subscribe
Google Reader or Homepage

del.icio.us CodeBetter.com Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl CodeBetter.com Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of Devlicio.us
Red-Gate Tools For SQL and .NET

NDepend

SlickEdit
 
SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
LiteAccounting.Com
DevExpress
Fixx
NHibernate Profiler
Unfuddle
Balsamiq Mockups
Scrumy
JetBrains - ReSharper
Umbraco
NServiceBus
RavenDb
Web Sequence Diagrams
Ducksboard<-- NEW Friend!

 



Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers

 

Community Server (Commercial Edition)