Martinicity: The Unselfish Act of Writing Tests Mike Blake tag:www.martinicity.net,2005:Typo Typo 2007-02-14T21:09:18+00:00 Mike Blake urn:uuid:d3a23de4-6d31-4890-aaf1-7e6e04e61f32 2007-02-14T21:07:00+00:00 2007-02-14T21:09:18+00:00 The Unselfish Act of Writing Tests <p> ####ORUG At this months <a href="http://www.orug.org">Orlando Ruby User&#8217;s Group</a> meeting, I did my <a href="http://www.apptrain.net/testing/img0.html">Testing on Rails</a> presentation. In it I touched on just some of the benefits of having an automated suite of Unit, Functional, and Integration tests. <p> <p>!<a href="http://www.apptrain.net/testing/img4.jpg">Benefits of Testing</a></p> <p> Later I thought of another major benefit. Tests help other people on the project, in addition to the author of the test. <ol> <li>Good Habits are Contagious</li> </ol> <p>Recently I had the opportunity to work on a project with <a href="http://blog.harrisreynolds.net/">Harris Reynolds</a>. Harris did something very important that sadly, you don&#8217;t see on every Rails Project. He wrote a unit test. Lot&#8217;s of us wrote tests , but this particular test stood out for two reasons. The first was when it was written.</p> <ol> <li>Writing Tests First</li> </ol> <p>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 <code>rake test:recent</code> which runs all recently changed tests in a Rails application . The error took me right to the problem, and I immediately fixed the bug.</p> <ol> <li>Testing a Deployment</li> </ol> <p>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&#8217;t been installed correctly on the new machine. Harris&#8217;s test told the problem straight away, and saved time once again.</p> <p><b>Unit Testing: the gift that keeps on giving.</b></p> <p>Thanks Harris!</p>