test driven development by example

test driven development by example is a classic on test driven development (TDD) by Kent Beck. It explains TDD itself, not the xUnit frameworks (although one of the examples is developing a basic xUnit framework), there are other good books on that.

test driven development by example

Its motto is 'Clean code that works - now'. It doesn't explain TDD with dry rules to follow, but instead it dives right into the subject, by using TDD in two example projects. The first, the (now famous) Money example, teaches the reader to write tests before writing the code, and how to grow a design organically. All the important parts of TDD are explained here, such as the test-compile-run-refactor cycle, refactoring, removing duplicates, and triangulation. The second example, the xUnit example, in which the unit tests are used to develop the testing framework itself (his favorite way of learning a new language), shows how to test more complex logic. A third part, Patterns for test driven development, shows patterns for choosing what to test, refactoring, and briefly touches on subjects like mock objects, child tests, testing error handling, clean check-in, using factory methods, composites, etc.

test driven development by example shows how to use very little steps in writing tests, which may surprise experienced developers, but after some more examples you begin to understand why. Writing return statements with hardcoded values, like 'return 5;' just to make the test work, seems even more bizarre at first, even if you know it will be taken care of with triangulation, but it's all part of using very little steps.

The examples that Kent Beck gives are in Java and Python, but that shouldn't matter, even if you don't know these languages, the focus is on test driven development itself and the code is easy to understand. I know a reader who tried the examples in another language, and was very pleased with what he learned this way.

Order test driven development by example by Kent Beck on Amazon.