Experienced practitioners, particularly those that have been involved in helping other developers learn TestDrivenDevelopment; note a life-cycle to its learning and adoption:
- The developer starts writing unit tests around their code using a test framework like JUnit,1 or NUnit.
- As the body of tests increases the developer begins to enjoy a strongly increased sense of confidence in their work.
- At some point the developer has the insight (or are shown) that writing the tests before writing the code, helps them focus on only writing the code that they need.
- The developer also notices that when they return to some code that they haven’t seen for a while, the tests serve to document how the code works.
- A point of revelation occurs when the developer realises that writing tests in this way helps them to “discover” the API to their code. TDD has now become a design process.
- Expertise in TDD begins to dawn at the point where the developer realizes that TDD is not about testing, it is about defining behaviour.
- Behaviour is about the interactions between components of the system and so the use of mocking is fundamental to advanced TDD.
This progression is very common, but while most developers find their way to step 4, many miss the big wins found at steps 5, 6 and 7.