Test-Driven Development by Example

March 13, 2007 @ 3:17 | In Books, Programming | No Comments | del.icio.us digg devbump rss
Test Driven Development book

Test-Driven Development by Example
Author: Kent Beck
Pages: 220
Published: 2003

Test-Driven Development is part of the Extreme Programming movement, created by Kent Beck (author of the book), Ward Cunningham and Ron Jeffries. It is an iterative technique to develop software where you only code the things that are strictly necessary.

If you want a new feature in your code you write a test using that feature and later you write the new code that makes that test work properly. You write new code only if an automated test has failed. And iteratively you continue until you finish all the requisites. Between test and test you always have a code that compiles and works.

This is described by Kent Beck as the Red/Green/Refactor rule:

  • Red - Write a little test that doesn’t work, and perhaps doesn’t ever compile at first
  • Green - Make the test work quickly, committing whatever seems necessary in the process
  • Refactor - Eliminate all of the duplication created in merely getting the test to work

The book itself is written using this philosophy. With small steps the first part of the book teachs you the technique with a very simple example. The second part describes a more complicated example and introduces a framework for writing tests. Third part is dedicated to patterns for Test-Driven Development.

Part two and three of the book were boring to me but I really enjoyed the first part of the book. It is an example very well written and very easy to read that demonstrates you the heart of the technique. I like the incremental approach of writing source code that always compiles (something that I have been using for years) against the opposite technique: writing tons of code at first and later spending hours (even days) making it to compile.

Although you probably won’t be able to put into real practice the entire philosophy (I’d like to see a real project 100% Test-Driven Developed) you can learn very valuable things from this book: tests are useful and simplicity is your friend.

Rating: 8 / 10



Fri, 25 Jul 2008 11:40:57 +0200 / 21 queries. 1.153 seconds / 2 Users Online

gentoo link wordpress link apache link PHP link website stats

Theme modified from Pool theme. Valid XHTML and CSS