Skip to content
Zeger Hendrikse edited this page Aug 5, 2023 · 20 revisions

There is more to TDD than “red, green, refactor”

Although most people have heard of the slogan “red, green, refactor”, it is only a small part of what defines TDD. From its inception, TDD and eXtreme Programing have always been closely knitted.

TDD is best understood as a set of skills and heuristics that enable you to guarantee that every line of the code base contributes to the expected behavior while clearly expressing its intent at the same time.

But how do these skills and heuristics then relate to the well-known red-green-refactor slogan that is almost always the first response when people are asked to explain TDD? The short answer is that the aforementioned skills and heuristics are constantly being applied while traversing the red-green-refactor loop.

For example, consider the following skills, heuristics, and principles (to name just a few):

  • Start a test by writing the assertion first → heuristic for the “red” step.
  • The DRY principle (don’t repeat yourself) → principle while refactoring.
  • Refactoring in (extremely) small steps → profound skill in the “refactor” step.
  • Faking and cheating → heuristic to make a test pass, i.e. the “green” step.
  • 0, 1, N → heuristic to generalize production code.

But how on earth are all these skills, principles, and heuristics then connected and practically applied when practicing TDD?

To illustrate this connection, consider the diagram below (inspired by Rob Westgeest). When going through the regular red, green, and refactor phases of TDD, you’ll notice that there are many heuristics, skills, and principles continually being applied. This happens very consciously at first but becomes gradually more ingrained in your way of working as you become more fluent in practicing TDD. Indeed, it is much like playing the piano!

Heuristics

It is exactly this combination of countless skills and heuristics that increases the quality of your code so significantly (as we are effectively building quality in) and hence boosts your confidence to such an extent that you are able to promote your changes to production whenever is needed. Perhaps the best and most fun way to practice all of these skills is by participating so-called coding katas.

Last but not least, TDD is a lot of fun. This repository contains more than enough materials to learn everything about TDD and get up and running in the wink of an eye!

Clone this wiki locally