Rake stats: code to test ratio

I was curious what everyone’s code to test ratio is with running rake
stats. I’m trying to find what a typical ratio should be.

Daniel Salo wrote:

I was curious what everyone’s code to test ratio is with running rake
stats. I’m trying to find what a typical ratio should be.

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…


Phlip
Redirecting... ← NOT a blog!!!

Phlip wrote:

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.

Jeff

Daniel Salo wrote:

I was curious what everyone’s code to test ratio is with running rake
stats. I’m trying to find what a typical ratio should be.

It may be interesting, but it is not informative or useful. The number
of tests and the number of lines in those tests should reflect what is
required to ensure your application is working correctly.

In a similar way, the number of lines in the application is sort of
interesting but has little bearing on the functionality or usability the
application may have.

The only time I have used either of these numbers is to demonstrate how
efficient rails is in comparison to another platforms. Striving for a
particular number or ratio is fruitless IMHO.

Jeff wrote:

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.

Our industry in general is recovering from the days when bosses tracked
LOC as “progress”.

Just between engineers, as a ratio, when we are curious, it’s project
information like any other…


Phlip

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.]

RSL