Understanding the Red-Green-Refactor workflow
The Red-Green-Refactor workflow (or cycle) is a process that defines the mechanics of how you write software. It has enduring appeal because it has helped so many developers be more productive by providing structure to their day-to-day jobs.
You do your work by making repeated cycles through the workflow until your software is complete. Red-Green-Refactor also lends itself to pairs and groups of developers working together, because it gives you a way to organize your discussion and decision making.
Figure 2.1 shows the workflow. It has three parts:
- Red: To begin, you write a failing test. This sounds easier than it is, because first you have to know what you’re intending to build.
- Green: Once you have a failing test, you make it pass. You strive to find the shortest route possible to solve the test.
- Refactor: Make it good. Take a step back and think about the design. Even though you took the shortest route there...