-
Notifications
You must be signed in to change notification settings - Fork 2
Home
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!
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!
This work is licensed under a CC-BY-SA-4.0 license. Attribution: github.com/zhendrikse/tdd.