The Rhythm of TDD
The cycles of TDD are short. Without all the chatter that accompanies this chapter’s example, each cycle of test-code-refactor is perhaps a few minutes. The increments of code written or changed at each step in the cycle are similarly small.
After you establish a rhythm with TDD, it becomes obvious when you’re heading down a rathole. Set a regular time limit of about ten minutes. If you haven’t received any positive feedback (passing tests) in the last ten minutes, discard what you were working on and try again, taking even smaller steps.
Yes, you heard right—throw away bad code. Treat each cycle of TDD as a time-boxed experiment whose test is the hypothesis. If the experiment is going awry, restarting the experiment and shrinking ...