-
Get a monthly update on best practices for delivering successful software.
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.
And on with the interview.
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.
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.
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.
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...
Automated testing is much easier and more valuable if you keep a tight feedback loop between your tests and your code.
Related posts:
Topics: Ruby on Rails, tdd, Test Driven Development, Testing
[...] The Testing Interviews [...]
Pingback by Ennuyer.net » Blog Archive » 2009-01-17 - Today’s Ruby/Rails Reading, Sunday, January 18, 2009 @ 12:08 pm