What is the Red-Green-Refactor cycle in TDD?

Answer

The Red-Green-Refactor cycle is the core TDD workflow: Red: write a test for a small, specific behavior that you're about to implement. Run it — it must fail (confirm it's actually testing something). A test that passes before code is written is meaningless. Green: write the minimum amount of production code to make the failing test pass. Don't write more than needed — resist the urge to over-engineer. The goal is just to make it green. Refactor: clean up both the test code and production code while keeping all tests green. Remove duplication, improve naming, extract methods, apply patterns. The test suite ensures refactoring doesn't break behavior. Repeat for the next behavior. The cycle should be short — minutes, not hours. This discipline produces: design that emerges from requirements (not speculation), complete test coverage for implemented features, and clean, refactorable code. Kent Beck: "Write tests until fear is transformed into boredom."