Red-Green-Refactor

loop pattern · maturity: established · risk: low

The test-first loop: write a failing test that encodes the requirement, write the minimum code to pass it, then refactor with the test as a safety net.

When to use

Feature and bugfix work in test-capable codebases; the strongest evidence trail per unit of ceremony.

Steps

StepWhat happensVerification
RedWrite a test that fails for the right reason.Test run, observed failing, failure message matches the missing behavior.
GreenWrite the minimum implementation to pass.Target test passes; full suite still passes.
RefactorImprove structure without changing behavior.Suite green after every refactor step.

Specification

Verification methodThe tests themselves: the loop's own output is its evidence.
Recovery behaviordiagnose-then-retry
ObservabilityTest run history is the audit trail.
InputsRequirement, Test infrastructure
OutputsTested implementation, Regression net
Risk level / maturitylow / established

Failure modes

  • Tests written after code assert the implementation, not the requirement
  • Agents modify the test to make it pass
  • Setup-heavy stacks tempt skipping straight to code

Assessment

The oldest loop in this library and still the highest evaluation-readiness per step. The agent-specific hazard is test-tampering, which is why boundaries like 'never modify the test to make it pass' appear in serious TDD skills.

Skills that implement this

Go deeper