From Kent Beck’s book Test-Driven Development By Example I’ve learned a few quite simple rules.

The two essential rules:

  1. Write new code only if there is a failing automated test
  2. Eliminate Duplication

The more systematic way of doing TDD:

  1. Add a test
  2. Run all tests and fail
  3. Make a little change
  4. Run tests and pass
  5. Refactor to remove duplication

This method can be broken down even further to:

  1. Red – write a failing test
  2. Green – make it pass
  3. Refactor – remove duplication

This is more widely known as the TDD Mantra.

The ability to work in small steps thus strengthens our confidence in the software we build.

In programming, if you fear the unknown, write some tests!

Advertisements