Test-Driven Development

SIGCSE 2006 Workshop Companion Web Site

What Is Test-Driven Development?

Test-driven development (TDD) is all about writing "clean code that works." Here are some quotes (from Kent Beck) that intuitively describe TDD:

The style here is to write a few lines of code, then a test that should run, or even better, to write a test that won't run, then write the code that will make it run.

...

[After figuring out how to write one small piece of code ...] Now, instead of just coding on, we want to get immediate feedback and practice "code a little, test a little, code a little, test a little." [... So we immediately write a test for it.]

TDD grew out of Extreme Programming, ad evolved from the simple XP idea of "build a little, test a little" during coding. Basically, your code always has a complete set of tests that exercises its capabilities, and you write new tests as you add to your code. Practiced systematically, TDD:

Learning About TDD

To learn more about TDD, the first place to start is the following (easy to read) classic:

While the Java stuff may not apply in every language, the basic practices and emphasis of TDD are well-presented. Next, the following two articles are required reading for getting a good overall view of TDD:

If you'd like to dig into TDD more deeply, you might find the following sources useful:

Finally, if you want to use TDD in a language other than Java (it works in most!), you might want to consult XProgramming.com's software page. Look in the "Unit Testing" section for many links to various XUnit implementations (e.g., JUnit-like framework ports to support TDD in various languages).