TDD Workflow
When This Skill Activates
- •When writing any new functionality
- •When modifying existing behavior
- •When fixing bugs (write the reproduction test first)
This is a background skill. It should be internalized and applied automatically during all implementation work.
The Cycle: RED → GREEN → REFACTOR
RED — Write a Failing Test First
- •Write a test that describes the DESIRED behavior.
- •Run it. It MUST fail.
- •If it passes, either:
- •The feature already exists (verify and skip)
- •The test is wrong (fix the test)
- •The failing test is your specification. It defines "done."
GREEN — Write Minimum Code to Pass
- •Write the simplest, ugliest code that makes the test pass.
- •Do NOT add extra features, abstractions, or polish.
- •Do NOT handle edge cases that aren't tested yet.
- •Run the test. It MUST pass.
- •Run ALL tests. None may have broken.
REFACTOR — Clean Up
- •Now improve the code: remove duplication, improve naming, simplify logic.
- •After each change, run ALL tests. They must all still pass.
- •If a test breaks during refactoring, undo the last change.
- •This is NOT the time to add features.
Anti-Patterns (Do NOT Do These)
- •Writing implementation first, tests after → Tests become afterthoughts
- •Writing all tests up front → Too rigid, doesn't adapt to discoveries
- •Skipping RED phase → "It should work" is not TDD
- •Making tests pass by changing test expectations → Defeats the purpose
- •Adding features during REFACTOR → Scope creep
Test Quality Guidelines
- •Test BEHAVIOR, not implementation details
- •Each test should test ONE thing
- •Test names should read as specifications:
should return 404 when user not found - •Tests must be independent — no shared mutable state
- •Tests must be fast — mock external dependencies