Mar 04
2008

Automated testing is the shit

Up until a week ago I never really understood the draw of automated testing.

I come from the school of manual test scripts that you run through before every new release.

Write down things you should do. Walk through the app, click on stuff, make sure it works.

Slow, error prone, and time consuming – but it’s what I knew. That all changed last week when I dusted off my copy of Extreme Programming Installed and burned through the remainder I had failed to read previously.

I finally jumped into unit testing in Ruby on Rails with Mocha and Autotest. I’m steadily catching up on tests for Cashboard and it’s amazing the things you find when you start automated testing.

Mocha

Mocha is a library useful for “mocking” or “stubbing” code that you want to verify executes, but not really run. Useful for network calls, sending emails, and all those other things you want to make sure get called by your test code, but don’t actually run.

Autotest

Autotest is part of the ZenTest suite. You run it from the root of your project and it monitors your code for any changes made.

I keep it running in a terminal next to TextMate and watch it spring into action and run my tests immediately after I save them. Major time saver.

For extra nerd points you can even get Autotest to display notifications with the dude from DOOM, letting you know if your tests passed or failed.

Nice that DOOM guy is now boosting my productivity, instead of draining it in years past. (How many hours did I waste blasting monsters in that thing?)

Security in testing

I’ve already cornered a few long-standing bugs via test code, and I’m on my way to full coverage for all units.

It feels good, and secure. If you’re programming in RoR and aren’t testing today…make the jump. Dig in, learn it. It’s worth the headache and trouble you’ll save in the long run.

Side note

Does anyone else buy massive amounts of books from Amazon, read a few chapters, then let them sit? I’ve got to stop doing that and finish off the ones I purchase.

Written by Seth B

As the Founding Partner of Subimage LLC, Seth spends most of his days improving Cashboard. Occasionally he finds time to write about music, design, startups, and technology.

Tagged: ruby, tdd, agile