Daniel Salo wrote:
Code LOC: 2233 Test LOC: 2173 Code to Test Ratio: 1:1.0
Note if this were a greenfield project (no legacy stuff like HTML to slow it
down) the test rate would be much higher...
I hate any comparisons that involve lines of code.
For a while when I first discovered rake stats, I justified it to
myself by saying well, they're only using it to get a ratio, not
absolute lines of code; so it must be ok.
But lately I've decided that it's still ridiculous. How can lines of
code at all compare to lines of testing code?
If it takes me 6 lines to implement a method, do I really have to come
up with 6 or more assertions to get the ratio right? What if two
assertions test everything I need to about that method? Or what if I
really need 10, then 6 is actually not enough.
So please don't strive for any particular ratio. It's just there for
informational purposes, no more and no less.
I agree with you, Jeff. It’s just numbers really. A guide. You know if you’re testing enough 'cause you’re testing a lot. As a newcomer to using “rake stats”, I was obsessed by getting that ratio above 1:
1.0. I soon discovered that [kinda counterintuitively] the DRYer you make your tests [ie, writing out common assertions to test_helper.rb, etc] the LOWER your ratio will be. Good DRY tests ratio looks a lot worse than a repetitive, redundant [yes, I know] one. I still use “rake stats” but only out of curiosity instead of looking for a validation of how good a coder I’m being. [Yes, I need affirmation like that sometimes.]