Test-Driven Development

By Example

~ Kent Beck, 2002

Two simple rules:

TDD mantra: Red/Green/Refactor

TDD cycle:

  1. Write a test (Red) - Write a little test that does not work
  2. Make it run (Green) - Make the test work quickly, committing whatever sins necessary in the process
  3. Make it right (Refactor) - Eliminate all of the duplication created in merely getting the test to work

Three TDD strategies for getting to green:

  1. Fake It - Return a constant and gradually replace constants with variables until you have the real code.
  2. Obvious Implementation
  3. Triangulation - Generalize code when we have two examples or more