Hybrid TDD
Core principles
- Test behavior through public interfaces, not internals.
- Work in vertical slices: one test → one implementation.
- Keep CI green on every commit.
- No speculative tests or speculative code.
Workflow
1) Plan with the user
Before coding, confirm:
- Interface changes needed
- Behaviors to test first (prioritized)
- Good seams/deep-module opportunities
- The first tracer bullet
2) Tracer bullet loop (feature work)
For each behavior:
- RED: write one failing behavior test
- GREEN: make the smallest change to pass
- MICRO-REFACTOR (optional): only while green
- Commit with a clear message showing progression
Rules:
- One test at a time
- Minimal code for current test only
- Prefer integration-style behavior tests
- Avoid coupling tests to implementation details
3) Bug-fix protocol (two commits)
- Add regression test that reproduces the bug and asserts intended behavior.
- Keep branch green by using strict
xfail(XPASS must fail) or equivalent explicit expected-failure mechanism. - Commit the regression test first (reviewers can verify the bug is captured).
- Implement the fix, remove expected-failure marker, verify test passes.
- Commit the fix separately.
4) Refactor phase
After target behaviors are green:
- Extract duplication
- Deepen shallow modules behind simpler interfaces
- Run tests after each refactor step
- Never refactor while red
Guardrails checklist
- [ ] Test describes observable behavior
- [ ] Test uses public interface
- [ ] Test survives internal refactor
- [ ] Code is minimal for this step
- [ ] No red suite without explicit expected-failure marker
- [ ] Deterministic tests; avoid hypothetical edge-case sprawl