TDD Workflow

Test-driven development practices based on the superpowers methodology.

The Iron Law

“No production code without a corresponding failing test first. Code written before tests must be deleted and reimplemented properly.”

RED-GREEN-REFACTOR Cycle

PhaseActionVerification
REDWrite one minimal test demonstrating required behaviorRun tests, confirm failure for expected reason (not typos)
GREENImplement simplest code satisfying only the testAll tests pass with clean output
REFACTORRemove duplication, improve namingTests still pass

Testing Anti-Patterns to Avoid

1. Testing Mock Behavior

Verifying mocks exist rather than actual code works.

  • Fix: Test real components or remove the mock

2. Test-Only Methods in Production

Adding cleanup methods just for tests.

  • Fix: Move to dedicated test utilities

3. Mocking Without Understanding

Over-mocking “to be safe” breaks real behavior.

  • Fix: Understand side effects first, mock at correct level

4. Incomplete Mock Structures

Partial mocks missing fields downstream code needs.

  • Fix: Mirror complete real API structure

5. Tests as Afterthought

Writing after implementation.

  • Fix: TDD - failing test first, always

Rationalizations to Reject

  • “Too simple to test”
  • “I’ll write tests after”
  • “Already manually tested”
  • “Keeping as reference”