Programming ≈ Fun

Written by Krešimir Bojčić

Test Driven Development By Example

I’ve made 20 minutes long screencast demonstrating my TDD technique.

I clearly remember the day that test driven development clicked with me although it was seven years ago. I had such a hard time understanding the motivation and the technique. It was Ron Jeffries article about (his bellowed example) bowling where he did test driven play-by-play. I remember thinking the whole time that he is crazy to go in such a small steps… but then in a split second it became crystal clear that it really is the fastest way to do it. The tests enabled him to be brave and to pull himself out of a really bad situation.

Although I knew the theory, it took a good example for me to get it.

Interestingly later on I’ve read that Robert C. Martin (aka Uncle Bob) had the same feeling when Kent Beck was showing him the technique. Anyhow I’ve slapped together a screencast that can explain why and how to do TDD from my perspective. It’s not much, but at least it’s original :)

English is obviously not my native tongue… so I end up breaking my tongue a lot… but other than that I think it’s rather educational. It you are still up for it you can check it out here. Just make sure to watch HD version…

Pay attention how I didn’t listen to tests in the beginning, and how completely lost I was because of it, trying to fix the thing that I thought was a problem. The poor test was yelling at me the whole time so I finally manged to figure it out!
require File.join(File.dirname(__FILE__),'node')

describe Node do
  it 'should be able to open' do
    subject.open
    subject.opened?.should == true
  end

  it 'should be able to close' do
    subject.close
    subject.opened?.should == false
  end

  it 'should be open by default' do
    subject.opened?.should == true
  end
  ....

Comments