©Vladimir Levin

TDD: Test-Driven Development

What is TDD

TDD, or Test-Driven Development is is one of the core practices of Extreme Programming (XP), but it is a useful practice even on its own. TDD is a programming practice in which all "production" code is preceded by an automated test (also often called a unit test). The goals of TDD are as follows:

Basic Loop of TDD

  1. Write a test and make sure it fails
  2. Write code to make the test pass
  3. Examine the design and refactor (see note) if necessary, then make sure tests still pass.
Note: Refactoring should be done when the design starts to look bad (long methods, unclear responsibilities) or when making changes or writing additional code becomes cumbersome. Refactoring is the process of modifying the structure of code without changing its underlying purpose. A simple example is breaking up one long function into multiple shorter functions, each with a clear responsibility

TDD is not

Drawbacks of TDD