The Unselfish Act of Writing Tests

Posted by Mike Blake Wed, 14 Feb 2007 21:07:00 GMT

ORUG

At this months Orlando Ruby User’s Group meeting, I did my Testing on Rails presentation. In it I touched on just some of the benefits of having an automated suite of Unit, Functional, and Integration tests.

Benefits of Testing

Later I thought of another major benefit. Tests help other people on the project, in addition to the author of the test.

Good Habits are Contagious

Recently I had the opportunity to work on a project with Harris Reynolds. Harris did something very important that sadly, you don’t see on every Rails Project. He wrote a unit test. Lot’s of us wrote tests , but this particular test stood out for two reasons. The first was when it was written.

Writing Tests First

Harris had found a bug in a model object that I had created. To notify me, he checked in an assertion that failed, then emailed me. This saved me time searching thought and remembering code I had written. I simply typed rake test:recent which runs all recently changed tests in a Rails application . The error took me right to the problem, and I immediately fixed the bug.

Testing a Deployment

The second reason I remember this test happened at least a month later. The application was being deployed to a new machine, and the test failed. The particular model object being tested pointed to a different database that the rest of the application, and it turned out that that database hadn’t been installed correctly on the new machine. Harris’s test told the problem straight away, and saved time once again.

Unit Testing: the gift that keeps on giving.

Thanks Harris!

Posted in  | Tags , , ,  | no comments

Comments

(leave url/email »)

   Preview comment