Chapter 11. Test-Driven Development (TDD)

You can build very large and complex systems that work without doing any modeling at all.

Test-driven development (TDD) (Beck 2003; Astels 2003), also known as test-first programming or test-first development, is an evolutionary approach to development whereby you must first write a test that fails before you write new functional code. What is the primary goal of TDD? One view is that the goal of TDD is specification and not validation (Martin, Newkirk, and Koss 2003). In other words, it's one way to think through your design before your write your functional code. Another view is that TDD is a programming technique. As Ron Jeffries likes to say, the goal of TDD is to write clean code that works. I think that there is merit in both arguments, although I leave it for you to decide.

This chapter discusses the following topics:

  • The steps of TDD

  • TDD and traditional testing

  • TDD and documentation

  • Test-driven database development

  • TDD and Agile Model-Driven Development (AMDD)

  • How does TDD work?

How Does TDD Work?

A significant advantage of TDD is that it enables you to take small steps when writing software. This is a practice that I have promoted for years (Ambler 2001a; Ambler 1998a) because it is far more productive than attempting to code in large steps. For example, assume that you add some new functional code, compile, and test it. Chances are pretty good that your tests will be broken by defects that exist in the new code. It is much easier to find ...

Get Agile Database Techniques: Effective Strategies for the Agile Software Developer now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.