| name | tdd-enforcer |
| description | Enforce Test-Driven Development (TDD) RED-GREEN-REFACTOR cycle when user writes code, implements features, or fixes bugs. Trigger when user mentions "implement", "add feature", "create function", "build", or starts coding without tests. Apply to Python, TypeScript, JavaScript, and all languages with testing frameworks. |
| allowed-tools | Read, Grep, Glob, Bash, Write |
TDD Enforcer
Enforce tests BEFORE implementation using RED-GREEN-REFACTOR cycle.
🔗 Production Framework: For strict TDD enforcement in production projects, see obra/superpowers which provides battle-tested, production-grade TDD enforcement with deeper integration. This skill is a lightweight learning alternative for understanding TDD principles and integrating with Claude Code's native skill system.
Trigger Conditions
Activate: "implement", "add feature", "create function", "build", "let's code this", writes production code without tests
Skip: Exploration/research, documentation, refactoring tested code, "skip tests" (but warn)
RED-GREEN-REFACTOR Cycle
RED: Write Failing Test First
- Understand requirement
- Write test describing desired behavior
- Run test → confirm FAIL (for right reason, not syntax)
GREEN: Minimal Implementation
- Write simplest code to pass test
- No extra features or future-proofing
- Run test → confirm PASS
REFACTOR: Improve Quality
- Improve readability, remove duplication
- Run tests after EACH change
- Never add new behavior during refactor
Output Format
def test_[function]_[scenario]_[outcome]():
[setup]
[call]
[verify]
def function():
[minimal_code]
def function():
[better_code]
TDD Violation Detection
If user writes production code without test:
⚠️ TDD VIOLATION: Writing code without test.
Let's write the test first. What behavior should we test?
Don't
- Write implementation before tests ("I'll add tests later")
- Skip tests for "simple" functions
- Test implementation details instead of behavior
- Write tests that always pass
- Commit code without tests