The TDD Cycle: Red-Green-Refactor

When doing TDD, you repeat a short cycle of the following:

  1. Write a test (“red”).

  2. Get the test to pass (“green”).

  3. Optimize the design (“refactor”).

images/RedGreenRefactor.png

This cycle is often summarized as red-green-refactor, a phrase that stems from unit testing tools used for TDD. Red (fail) and pass (green) derive from SUnit (the first unit testing tool designed to support TDD[8]) and similar GUI tools that use the colors to provide immediate feedback on test results. The text-based output of Google Mock uses red and green when executed in a terminal with color support.

During the refactoring step, you seek to ensure your codebase ...

Get Modern C++ Programming with Test-Driven Development now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.