Monday, September 27, 2004

code smell: tests/production LOC ratio

disclaimer: this reasoning assumes the project is striving for 100% production code coverage by unit tests.

As noted elsewhere, optimal lines of code (LOC) ratio for production code vs unit tests is about 1:1. I wonder, does significant deviation on either part indicate a code smell?

First, consider the case when the ratio is about 5:1. This could mean two things:
  1. Code coverage is poor (a good guess -- about 20-30%). No good, obviously.
  2. If code coverage is in 80-95%% range than we most probably have some flavour of acceptance (functional) tests not a canonical unit tests. Which is no good either.
Second scenario - when the ratio is 1:3 or even 1:5. Though less common, I still got into this situation from time to time. From my experience, this is usually a sign of a code smell:
  1. Elaborate setup code and/or a lot of stubs may indicate not well factored class hierarchy.
  2. Lengthy test cases for particular production methods can indicate a heavyweight class waiting for the Extract class refactoring to be applied.
Usually this ratio for my own code varies between 2:1 and 1:2. If it grows more, I tend to pay attention to either tests or the code itself. My experience here is mostly Python-based, in more verbose language like Java these figures may be a bit more vague.

PS: May be a "design smell" is a more appropriate term here?

update: My post's arguments were completed thrashed at I'm still trying to figure out how much I (dis-)agree with them.


Blogger Steve Austin said...

Interesting blog. I have a free xml editor blog.

6:50 PM  
Anonymous Anonymous said...

“We cannot live for ourselves alone. Our lives are connected by a thousand invisible threads, and along these sympathetic fibers, our actions run as causes and return to us as results.”
- Herman Melville

RSS is the way of the Future...
rss feed directory

4:58 PM  
Blogger Mike said...


I found this new software:

This is perfect for free traffic, high ranking, backlinks etc.

Check it out!
You don't want to miss this one.

7:51 PM  

Post a Comment

<< Home