Unit test lines of code

I’d like to know people’s opinions.

I quite often find that when I’m doing TDD, I end up with as much test
code as implementation, or more.

I don’t think I’m testing stupid things in my tests - I usually write
the tests incrementally, imagining I had the thing I’m testing, and
writing tests that exercise its functionality.

I’ve heard people say “those crazy unit test devotees - what’s the point
if you’ve got more test code than implementation?!”, and I wonder how
other people feel?

My take is it’s probably a case by case thing, but in the cases I’ve
come accross, I’ve been very comfortable with greater lines of test code
than implementation. I’ve felt the balance is right.

Cheers,
Benj

My accepted ratio is 2 lines of test code to 1 line of actual code. If
you
have 1:1, then you’re definitely not testing enough (edge cases, failure
cases, etc). I’ve pulled a 4:1 ratio on a few Rails sites I’ve worked
on,
and even then I could add more edge case testing. As for those who
complain
about LOC, well they obviously don’t care about quality of code, just
getting things done as fast as possible. I would recommend staying far
away
from such people.

Jason

On 7/12/07, [email protected] [email protected] wrote:

I’d like to know people’s opinions.

I quite often find that when I’m doing TDD, I end up with as much test
code as implementation, or more.

I don’t think I’m testing stupid things in my tests - I usually write
the tests incrementally, imagining I had the thing I’m testing, and
writing tests that exercise its functionality.

I do not have a lot of experience let me just count
Project1 all tests running, testcode 1000 lines, production code 300
lines
Project2 all tests running, testcode 2000 lines, prod 1300 lines

However I feel that Project2 will end up with > 10klines of testcode
and <1kline of production code, because I need refactoring badly and
the testcases become fingerprints of the firewall rules on machines,
that means that the testcase is part of the production environment
which is quite nice to have but maybe an extreme case.

I’ve heard people say “those crazy unit test devotees - what’s the point
if you’ve got more test code than implementation?!”, and I wonder how
other people feel?
No idea :wink:

My take is it’s probably a case by case thing, but in the cases I’ve
come accross, I’ve been very comfortable with greater lines of test code
than implementation. I’ve felt the balance is right.
Agree with all these statements see above .

Cheers,
Benj

Cheers
Robert