Statistic: LOC:Test
Posted by Chad | Posted in Misc, TDD | Posted on 21-06-2010
3
For pure curiosity reasons, I wanted to know the ratio of lines of code to unit tests. I’m writing all production code in Java and tests in Groovy.
LOC
Finding the lines of code: grep -v -r –include=”*.java” “^[[:space]]*$” * | wc -l
Number of Tests
grep -r –include=”*Test.groovy” “@Test” * | wc -l
Results
LOC: 706, Tests: 82
This yields a ratio of: 8.6 to 1

What is up with the dates on your posts? I see “21-06-2010-05-2008″ which doesn’t make any sense to me.
I would remove comments as well for the Java source. Here is how I would do it:
grep -v ‘^[ \t]*\([ \t]*\|\/\/.*\)$’ `find -iname ‘*.java’` | wc -l
Notice I haven’t removed multi-line comments because that would be fairly difficult with grep.
Also, why are you comparing LOC with number of tests and not LOC with LOT (lines of test). I’m not sure if either of the numbers actually means anything.
One last note… 706 lines of code for Java seems really small. Do you really have 82 tests? :/
Not sure what’s going on with the dates. I’ll check that out.
This is just one module, but yes there are 706 lines of java and 82 unit tests in this module. I’m not sure either number means anything either. I just wanted to see what they’d look like.
dates fixed.