An exercise for pushing Test-Driven Development to its limits.
Originally by Keith Braithwaite.
https://github.com/sf105/tdd-as-if-you-meant-it
- Add a little test
- Run all the tests and watch the new one fail
- Make a little change
- Run all the tests and watch the new one pass
- Refactor to remove duplication
- Repeat until done
- This exercise turns up the TDD design constraints to full volume
- It's intended to show how unexpected designs can emerge from the process
- It's an exercise, it's not intended for everyday use
- It's suprisingly hard to get started
- Thinking about solutions is not getting feedback
- Feedback comes from tests
Therefore:
Run tests early
- No, much earlier than that
Run tests often
- No, much more often than that
"Improving the design of existing code"
Existing code that you know works
1] Also known as "Noughts-and-crosses"
- Write one new test: The smallest you can think of that seems to point in the direction of a solution.
- Watch it fail
- Make the test pass by writing the least implementation code you can in the test method
- Refactor as required. To create new structure that's not test code,
apply these steps very strictly.
- methods:
- (preferred)
Extract Method
to create a new method in the test class - (if necessary) Move code into an existing method
- (preferred)
- types:
- create classes only to provide a destination for
Move Method
. - Populate classes by moving definitions from tests, not the other way round.
- create classes only to provide a destination for
- methods:
- The person not typing makes sure that these rules are being followed exactly.
- check in on every green bar
- describe your current design thinking in the comment
- How did that feel?
- What is your code like?
- Any lessons learned?
Remember, this is just an exercise
There's a sample solution the candidate-solution
branch of this repository