# Unit test lines of code

**URL:** <https://www.ruby-forum.com/t/unit-test-lines-of-code/109233>\
**Category:** Ruby\
**Created:** [July 12, 2007, 4:33pm UTC](https://www.ruby-forum.com/t/unit-test-lines-of-code/109233 "2007-07-12T16:33:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [July 12, 2007, 4:33pm UTC](https://www.ruby-forum.com/t/unit-test-lines-of-code/109233/1 "2007-07-12T16:33:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [July 12, 2007, 4:42pm UTC](https://www.ruby-forum.com/t/unit-test-lines-of-code/109233/2 "2007-07-12T16:42:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [July 12, 2007, 4:47pm UTC](https://www.ruby-forum.com/t/unit-test-lines-of-code/109233/3 "2007-07-12T16:47:31Z")

</div>

On 7/12/07, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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 😉
> 
> 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
