Red-green-refactor

Red-green-refactor image
Red-green-refactor, also called the TDD cycle, is the loop at the heart of test-driven development: write a failing test (red), write just enough code to make it pass (green), then improve the code without changing its behaviour (refactor).

Why it matters: The cycle gives developers fast feedback on the design of their code. The tests it leaves behind are a useful side effect, though they don't guarantee complete safety or confidence.

In practice: Testers can work alongside the cycle. Before the failing test is written, they help decide what it should be. During green, they think through edge cases and explore new code. During refactor, they review testability and coverage with the developers.

Examples:

  • A tester exploring new code on a developer's machine during the green stage.
  • Reviewing test coverage with developers during refactoring.

Common pitfalls:

  • Skipping the refactor step, so code quality slowly degrades.
  • Treating TDD's unit tests as all the testing needed.

What role do testers play in TDD? Testers help decide what to test, explore the code as it's written, think about edge cases and user behaviour, and collaborate on where each test belongs.
Explore MoT
Test Forward 2027 ยท Software Quality in the age of AI image
Tue, 19 Jan 2027
Test Forward is one afternoon at Station F with the QA and engineering people closing that gap in their own teams.
MoT Software Testing Essentials Certificate image
Boost your career in software testing with the MoT Software Testing Essentials Certificate. Learn essential skills, from basic testing techniques to advanced risk analysis, crafted by industry experts.
Into The Motaverse image
Into the MoTaverse is a podcast by Ministry of Testing, hosted by Rosie Sherry, exploring the people, insights, and systems shaping quality in modern software teams.
Subscribe to our newsletter