Book Review: Test Driven Development

Kent Beck’s Test Driven Development: By Example
follows the mold of the XP books: fairly thin and $30. I’ve never read Beck’s XP book, but I’ve read a couple of the others. Those books all seem to rehash the same material. Thankfully, this book is not like that.

For people who’ve never done TDD: the idea is simple. You take tiny steps with your code, writing a test for something you want to accomplish, making the test pass as quickly as possible, and then removing any duplication of code that resulted. Beck calls this cycle “Red-Green-Refactor”, based on JUnit’s GUI that shows red for failing tests and green for passing ones.

I found this book to be useful and nicely designed. The first part of the book walks through a couple of example programs that are built up bit-by-bit. These examples provide a look into Beck’s style of producing code and take the notion of TDD from the theoretical to the practical.

The other major part of the book goes over design patterns and testing strategies. When you actually start doing TDD, you often find that certain constructs are not easy to test. Beck provides tips on testing different types of components. The general pervading philosophy is that if something is very difficult to test, it’s probably not designed correctly. Fix the design, and you should be able to write your tests.