Glossary
Glossary Red-Green-Refactor

Red-Green-Refactor

Also known as: red green refactor, tdd cycle, tdd loop
TechTestingMethodology

Definition

The three-step loop of TDD: write a test that fails (red), write the least code that makes it pass (green), then improve the code without changing its behavior while the test keeps it honest (refactor) — and go around again

Each step has a discipline the others depend on. Red proves the test can fail, so a green later means something. Green forbids gold-plating — the ugliest code that passes is correct here. Refactor is where design happens, and it is safe only because the bar is green when it starts and must be green when it ends. Skip red and the tests are decoration; skip refactor and the code is the first draft forever.

Tech
Red, green, refactorRedGreenRefactorRed — a test that failsProve it can fail first.Green — the least code that passesUgly is fine; passing is the job.Refactor — clean up, bar greenDesign happens here, under a green bar.
Kent Beck's loop: a failing test, the least code that passes it, a clean-up the test keeps honest — and around again, in minutes.

Minutes, not hours, per loop. The step size is the point: a red that took an afternoon to reach is a design decision that was made without the test's help.

Related Terms

  • a: Appearance
  • ?: Keyboard shortcuts