Test-Driven Development (By Example) - Kent Beck

| 0 Comments
Kent Beck demonstrates the testing side of XP by separating it out into its own simple methodology. Test-Driven Development is exactly what it says it is. The entire design and development effort is driven by the tests that you write and you're encouraged to write those tests first...

Parts one and two contain worked examples of Test-Driven Development. Some will probably say that they're too simple, but I've found that even the most complex domain usually ends up as relatively simple code if you develop in this way. It needs to be simple to be testable. One of the major advantages of writing tests as you write code is that you are forced to actually use your code very early on. If the interface is complex and hard to test then it's probably also hard to use; as you simplify to make the code easier to test you improve the design of the API itself.

As someone who develops in this style, albeit with far less tests than I should have and often by taking far larger steps than shown in the book, what I found interesting was the way the design converged on something that was 'right' as the code and understanding grew; this is definitely true to reality. I think, perhaps, that some people may find the coding steps shown in the book too small and this may put them off. It may have been worth trying to take far larger steps initially and then cut them down to size as the difficulty in taking larger steps became apparant. Although Kent makes it clear that you can take larger steps and write more code as your confidence grows I find that what usually works best is just to 'walk faster' in smaller steps.

My one complaint with this book would be that unless you've programmed in this style before it's probably not obvious exactly how fast it's possible to go whilst taking such small coding steps. Although there are some graphs of time taken between test runs and number of lines changed per refactoring these possibly don't help make it clear that the worked example is probably less than a day's work in all. I think it would have been handy to have some timestamps at each change to show just how quickly things can happen.

Part 3 of the book contains details of some patterns that are useful in Test-Driven Development. Things like Mock Object and Self Shunt are great tools when testing and once you've discovered the power of being able to plug in mock up versions of your code's dependencies to enable testing your designs will change forever. The result being loosely coupled objects that are easy to test and, as a nice side effect, easy to use and reuse.

A useful and interesting book. If you come away from it feeling that it can't possibly work, give it a try anyway, you'll be surprised.

Leave a comment

About this Entry

Our first test was the previous entry in this blog.

One step closer to sanity is the next entry in this blog.

I usually write about C++ development on Windows platforms, but I often ramble on about other less technical stuff...

Find recent content on the main index or look in the archives to find all content.

I have other blogs...

Subscribe to feed The Server Framework - high performance server development
Subscribe to feed Lock Explorer - deadlock detection and multi-threaded performance tools
Subscribe to feed l'Hexapod - embedded electronics and robotics
Subscribe to feed MegèveSki - skiing