Sharing Our Passion for Technology
& Continuous Learning
Updated TDD Mantra
If you have ever practiced test driven development (TDD), then you are probably familiar with the TDD mantra – red, green, refactor. I’m a big proponent of TDD, but I think the TDD mantra is missing a fourth step.
In his book that introduced me to TDD, Test Driven Development: By Example, Kent Beck introduced the TDD mantra – red, green, refactor right away. In fact, you might have missed it, because it’s in the preface of the book. I think it’s a great mantra, because it represents the type of rhythm you can get into when doing TDD.
My favorite visual representation of the TDD mantra has been the red-green-refactor card created by Tim Ottinger for the Agile in a Flash blog:
However, as I stated at the top, I think the TDD mantra is missing a forth step. By design, TDD helps you create clean, simple code that only does what it needs to do. And that lends itself to the missing forth step: commit.
When you have competed the refactoring step, you are at a perfect point to commit. You have all your tests passing and you have introduced a small amount of change.
Making a commit at this point will improve your process even more. You will have autonomous chunks of work that are small and easy to understand. If you need to rollback or remove a change, it will be much easier to do because you have small independent commits to work with.
So I think the TDD mantra should include commit as the forth step: