Test-Driven Development
By Example
~ Kent Beck, 2002
Two simple rules:
- Write new code only if an automated test has failed
- Eliminate duplication
TDD mantra: Red/Green/Refactor
TDD cycle:
- Write a test (Red) - Write a little test that does not work
- Make it run (Green) - Make the test work quickly, committing whatever sins necessary in the process
- Make it right (Refactor) - Eliminate all of the duplication created in merely getting the test to work
Three TDD strategies for getting to green:
- Fake It - Return a constant and gradually replace constants with variables until you have the real code.
- Obvious Implementation
- Triangulation - Generalize code when we have two examples or more