Skip to content
May 13, 2011 / marrowboy


Do your tests drive it?

I got asked at work (again), wouldn’t development be quicker if we didn’t spend so much time writing tests? Surely, people argue, you can just get the code out quickly, then if it turns out to be worth keeping & building on you can chuck some tests around it to make sure it doesn’t get broken later on.

This is not what TDD is. This misses the point of TDD.

Thinking on the topics put forward in this blog (tl;dr: TDD is a self-correcting framework so you can do it well even on an off day), I realised that the benefits exist even when you are on top form. TDD separates the problems of coding into:

  1. what the code is supposed to do, and
  2. how it does it.

TDD does not allow you to concentrate on both those problems at once, and by removing that confusion it frees you to devote 100% thought-power to each in turn. This is one of the biggest wins of TDD for me, many of the other benefits (and there really are a lot*) are happy side-effects.

An analogy perhaps? Imagine writing code to be like driving a car, and thinking about what it should do like planning your route on a map. Yes, you can do both at once and it may even be quicker. But there is a much greater risk of getting lost, ending up in the wrong place or making an expensive mistake.

Image: jmorgan, flickr

Of course, the expensiveness of this mistake is completely dependent on the value of the project. If it is a pet project (or a breakable toy), then by all means do whatever you like! But if you place any value your project’s quality then why take the risk? Better be modest and careful.

*effects of TDD include, but are not limited to: better design, great test coverage, code which does exactly what is needed, increased developer confidence during refactoring, tests-as-documentation, simple & clean code. The list goes on…


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: