The Testing Interviews

Over at the Rails Prescriptions blog, I'm going to be posting a series of interviews with various and sundry Rails folks -- I'm cross-posting the first one here. To get the series started off, I've decided to use myself as a guinea pig and see if I can hold up to the grilling.

A couple of quick notes before I get to it.

  • The free e-book Getting Started With Rails Testing is now available. Check it out.
  • Those of you lucky enough to be in the sub-zero Chicago area can come to theChicago Ruby.org meetup Saturday, January 17th to hear lots of interesting stuff, including me talking about testing and Rails some more.

And on with the interview.

How did you get into writing tests regularly? Did you have a specific moment when you realized automated testing was valuable?

I started with automated testing very shortly after reading Kent Beck's original XP book. The XP book came out at a time when I was very receptive to the ideas -- I had just come off a project that had suffered from a lot of regressions and all the other kinds of pain that XP promised.

It didn't take long for me to see how much better my code was when I did a lot of testing... what was more surprising was how much more fun writing code test-first turned out to be. The quick feedback and the ability to clean up code with confidence turned out to be really satisfying.

What is your Rails testing process? What kinds of tests do you write, and what tools do you use to write them?

When I'm adding a new feature, I tend to start with a skeleton controller test that validates that the controller sets the right variables. I don't put much code in the controller, so then I move to testing the model for the new functionality. If the view logic seems to require it, then I'll add view tests after I get the view in place. I go back and forth between test and code pretty quickly, but sometimes the code will get ahead of the tests, especially when doing view layer stuff. I don't use integration tests very much at the moment.

I seem to have moved back into the core Rails test features recently, although I still use Shoulda for contexts and for the additional assertions. My most recent project used core Rails plus Matchy. I've also been using the various factory replacements for fixtures, which I like quite a bit.

What's the most interesting thing you've discovered about testing recently?

The biggest change I've made recently is using factories for generating test data, which makes the tests much more readable and stable by keeping the setup closer to the actual test.

Is there a tool you wish you had for testing that you don't think currently exists?

I wish I had a really good way of validating view logic, none of the ones I've tried have been completely satisfying. It'd also be nice to have more sophisticated coverage reports. Of course, these things might actually be impossible...

What advice would you give somebody looking to write more effective tests?

Automated testing is much easier and more valuable if you keep a tight feedback loop between your tests and your code.

Related posts:

  1. More Testing Interviews
  2. Rails Test Prescriptions is now on sale
  3. Again With The Cucumbers
  4. edge case city: requirements and testing dates for HR business logic
  5. Using Cucumber for Acceptance Testing

Comments: 1 so far

  1. [...] The Testing Interviews [...]

    Pingback by Ennuyer.net » Blog Archive » 2009-01-17 - Today’s Ruby/Rails Reading, Sunday, January 18, 2009 @ 12:08 pm

Leave a comment

Powered by WP Hashcash

Launch: Pathfinder Newsletter

    Get a monthly update on best practices for delivering successful software.

    Subscribe via email


    Subscribe via RSS      RSS icon

Topics

Search

WordPress

Comments about this site: info@pathf.com