Thursday, 1 September 2011

The obvious and not so obvious benefits of Test Driven Development

The basic principle of Test Driven Development is simple. You write your test code before you write your implementation code. Counter intuitive when you first hear it, but after you start doing it, you ask yourself why you haven't done it all these years (well, aren't most great ideas like that?)

The benefits are obvious and also not so obvious.

1. Big picture thinking. As you write your test case, you start thinking more about how your application is supposed to behave. You start catching gaps in the specification well ahead of implementation and integration.

2. Test coverage happens automatically, since unit testing is no more an afterthought - test code is the fist thing you write. By the time you are done with your application, you are left with a test suite that covers every line of code that your wrote.

3. Effective multi-tasking. Most important but not so obvious, TDD helps the developer focus on one thing at a time and there-by multitask effectively. Good multi-taskers possess a knack for dividing their time among multiple tasks throughout the day, while giving their undivided attention to each single task when they are at it. The challenge, where most people fail is in dividing tasks into small enough and un-ambiguos units, with un-ambigous results. TDD, I've found helps a great deal in this. Each test case defines an unambiguous unit of work, with an unambiguous result - the test either passes or fails.

4. Context switching. Another not so obvious benefit - even if you are distracted during your work by something urgent and you pick it back up hours or even days later, you know exactly where you left it by simply running your test suite and checking which test case is failing.

For a detailed reading on the subject>> http://jamesshore.com/Agile-Book/test_driven_development.html

No comments: