Notes on TDD as if you meant it
16 Dec 2019
Notes based on TDD as if you meant it by Keith Braithwaite.
The games Go and Tic Tac Toe are good candidates for practicing TDD as if you meant it.
Keith Braithwaites Rules
- Write exactly one new test, the smallest test you can that seems to point in the direction of a solution.
- See it fail.
- Make the test from (1) pass by writing the least implementation code you can in the test method..
- Refactor to remove duplication, and otherwise as required to improve the design.
If you want a new method, wait until refactoring time, then create new non-test methods by:
- Preferred: Do Extract Method on implementation code created as per (3) to create a new method in the test class, or
- If you must: Move implementation code as per (3) into an existing method.
If you want a new class- wait until refactoring time, then create non-test classes to provide a destination for a Move Method and for no other reason.
- Populate implementation classes with methods by doing Move Method, and no other way.
After some time coding:
- Contrast (look for differences) and compare (look for similarities) solutions.
- Consider the classes created. How many? How big? What mutable state?
- Consider the methods created. How many? How long?
- Apply a few different design metrics.
- How was the experience of working this way different from the usual?
- How could these ideas be applied to your day job?