Thursday, February 8, 2007

Test Driven Development

I'm often asked about the various aspects of Agile and XP. So I thought today would be a great day to write about one of my favourites - Test Driven Development - TDD. This is not to be confused with the other closely related Agile aspect of, Test Driven Bukkake - TDB (see a previous post of mine for more details on this topic).

The principle behind TDD is simple - you write a test for a component BEFORE you write the component itself. Now, people say to me, Crispin isn't this a bit strange? Surely it's just doing things in a completely wrong order just for the fucking sake of it? It's like writing with your left hand even though you are right handed. Sure it can be done, but why bother with all the hassle and try pretending it's any good?

I simply smile at these simpletons and explain that without a test the component does not even exist (thanks Bent Keck). Further the component is useless. Remember, in Agile, what really matters is to know that you have used Agile/XP practices. Delivering the component (or anything else for that matter) is secondary.

Infact, I use the principles of TDD in every aspect of my life. In the morning I go to the bathroom, pull down my pants and wipe my ass with toilet paper (well its actually hard tracing paper since I'm heavily into Mocking objects). Then I take a shit. Finally I pull up my pants and go away. Sure, this does leave me with my underwear stuck solid to my crack due to the shit on my pre-wiped ass sticking.
The way I see it is that if I don't wipe my ass first then the shit does not actually exist. But I feel this is a small price to pay for achieving Agile excellence.