Behavior Driven Development

Today at SD West 2006 I took a hands-on session with Dave Astels on using rSpec. Dave’s primary message was we shouldn’t be talking about the word test in test driven development, but we should focus on behavior. Really when you’re doing TDD you’re specifying what the code should do not verifying that code works.

It’s an argument that seems to be picking up steam which is partly the idea of changing Test Driven Development to Test First Design or Test Driven Design. rSpec is essentially a replacement for xUnit in Ruby that focuses on nice English syntax for expectations in the form of:

should.have.at.least(5).items

I’ve seen something like this in Java as well with the JBehave project or Agiledox, but rSpec seems to be making some pretty nice progress. The exercise was to implement the game of Deflexion with a full set of expectations. It was a pretty well thought out exercise for a half-day tutorial and Dave was able to spend time wandering around answering questions effectively.

The surprising thing was I paired up with another developer who gets to do a lot of XP in his day job and we really marched our way through the tutorial. We managed to get through 24 tests, I mean expectations, in about 2.5 hours. Not that surprising unless you consider I’m a relative newbie to Ruby and he was a complete newbie, though probably a better pure coder. As a bonus I understand Ruby modules and their syntax a lot better now.

Anyway I’ll be working my way through the complete tutorial tonight, because Ruby and behavior-driven development is just a lot of fun.