However, my mental model for approaching TDD I think is much simpler than the approach presented here. It basically is:
Do I _really_ understand the design implications of the unit I'm about to develop?
- No: Play around and prototype, and learn about my design, don't worry about tests
- Yes: Throw away any prototype and then really do the unit test-first.
I found that I gravitated towards this process after I learned (partly thanks to blogs from Uncle Bob Martin) that unit tests are really formal design specs. They are so formal and specific that they are expressed in code- a program describing what your program does. Before you can write one of those (or as many as your unit needs), you need to have a very precise concept of how you are about to proceed, and what exactly the product code is about to do.
The benefit of this process is that I prefetch a really deep understanding of the system I'm building. This leads to less bugs, and it leads to sensible, well-documented, and meaningful tests. It just takes a bit of discipline to follow at first, when you're not used to working this way.
Some argue that it takes longer to write code this way, especially when I throw away my hard-earned working prototype! It does take a little longer at first, but:
- Once I know the answer/outcome I seek, the tested version comes out way faster than the prototype.
- I spend much less time later on fixing my own bugs, which I learned are mostly due to my own lack of understanding the full dimensions of my system's design.