# Writing good test suites?

**URL:** <https://www.ruby-forum.com/t/writing-good-test-suites/74689>\
**Category:** Rails\
**Created:** [November 7, 2006, 10:52am UTC](https://www.ruby-forum.com/t/writing-good-test-suites/74689 "2006-11-07T10:52:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![phillyloco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/258eb7/32.png) [@phillyloco](https://www.ruby-forum.com/u/phillyloco)\
**Post date:** [November 7, 2006, 10:52am UTC](https://www.ruby-forum.com/t/writing-good-test-suites/74689/1 "2006-11-07T10:52:43Z")

</div>

Hello,

Before I started using rails, I never really was one to write unit  
tests or any types of test suites really. The more I’ve been using  
rails the more I started to write bigger and more comprehensive test  
suites (since it is so easy to do it with the rails framework). I  
pretty much picked up all my test writing habits as I wrote my tests  
this past year. I never looked into any tips, advice, or instruction  
on how to write good test suites.

So, I was wondering if anybody could offer any insight, pointers,  
links to resources, or anything really that could help me refine my  
approach to writing better test suites. How do you look at your  
software when you try are writing your test suites (it seems like it  
is a bit hard to do so objectively), how do you get good coverage,  
what kind of things do you always want to test in a web application,  
how do you share the load between unit tests and functional tests (for  
example, the unit tests for a Person model would have extensive  
validation coverage, but I’m guessing the functional test wouldn’t  
need quite the same level of depth).

In short, how do I know if I am writing good tests for my code?

Thanks,  
-carl

---

<div class="post-metadata">

**Author:** ![phillyloco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/258eb7/32.png) [@phillyloco](https://www.ruby-forum.com/u/phillyloco)\
**Post date:** [November 7, 2006, 10:53am UTC](https://www.ruby-forum.com/t/writing-good-test-suites/74689/2 "2006-11-07T10:53:03Z")

</div>

Check out

> **[Resources for Testing Ruby on Rails](https://bparanj.blogspot.com/2006/11/resources-for-testing-ruby-on-rails.html)**
>
> 1. A Guide to Testing the Rails 2. Test First Programming with Ruby 3. Ruby on Rails Testing Cheat Sheet 4. Testing Rails Apps - Mike Clar...

---

<div class="post-metadata">

**Author:** ![phillyloco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/258eb7/32.png) [@phillyloco](https://www.ruby-forum.com/u/phillyloco)\
**Post date:** [November 7, 2006, 10:53am UTC](https://www.ruby-forum.com/t/writing-good-test-suites/74689/3 "2006-11-07T10:53:40Z")

</div>

Read the tests in technoweenie’s code (  
[http://svn.techno-weenie.net/projects/](http://svn.techno-weenie.net/projects/) ). I had no idea what I was  
doing or  
what the big deal was until I started reading his code and looking at  
his  
tests. Then it was like that instant when you finally figure out what  
the  
weird little inexplicable thingy on your Swiss army knife is used for,  
and  
just for a minute you feel like you’re MacGuyver.

- foobario

---

<div class="post-metadata">

**Author:** ![phillyloco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/258eb7/32.png) [@phillyloco](https://www.ruby-forum.com/u/phillyloco)\
**Post date:** [November 7, 2006, 10:54am UTC](https://www.ruby-forum.com/t/writing-good-test-suites/74689/4 "2006-11-07T10:54:59Z")

</div>

> In short, how do I know if I am writing good tests for my code?

When you don’t have any bugs in your code, you know that you are  
writing good tests.

---

<div class="post-metadata">

**Author:** ![phillyloco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/258eb7/32.png) [@phillyloco](https://www.ruby-forum.com/u/phillyloco)\
**Post date:** [November 7, 2006, 10:55am UTC](https://www.ruby-forum.com/t/writing-good-test-suites/74689/5 "2006-11-07T10:55:24Z")

</div>

On 2-Nov-06, at 10:20 AM, removed\_email\_address@domain.invalid wrote:

> > In short, how do I know if I am writing good tests for my code?
> 
> When you don’t have any bugs in your code, you know that you are  
> writing good tests.

you might consider rcov - provides C0 test coverage analysis.

“Code coverage shouldn’t be abused (in few words, C0 coverage  
guarantees nothing) but it’s still useful for testing: it will at  
least tell you when your tests need more work, and most importantly  
where.” [1]

[1][eigenclass.org](http://eigenclass.org/hiki.rb?rcov)

J

---

<div class="post-metadata">

**Author:** ![phillyloco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/258eb7/32.png) [@phillyloco](https://www.ruby-forum.com/u/phillyloco)\
**Post date:** [November 7, 2006, 10:54am UTC](https://www.ruby-forum.com/t/writing-good-test-suites/74689/6 "2006-11-07T10:54:57Z")

</div>

Pragmmatic Unit Testing is an excellent book on this topic. Check it  
out.
