Use when implementing features/bugfixes to enforce strict TDD discipline - enforces RED (write failing test), GREEN (minimal code), REFACTOR cycle with no exceptions. Prevents ”test after” trap, catches rationalizations. Activates when user says ”implement”, ”let’s code”, ”write this feature”, menti
npx playbooks add skill xbklairith/kisune --skill test-driven-development
Write the test first. Watch it fail. Write minimal code to pass.
Core principle: If you didn't watch the test fail, you don't know if it tests the right thing.
Violating the letter of the rules is violating the spirit of the rules.
Always:
Exceptions (ask your human partner):
Thinking "skip TDD just this once"? Stop. That's rationalization.
NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST
Write code before the test? Delete it. Start over.
No exceptions:
Implement fresh from tests. Period.
RED (write a failing test) → Verify RED (watch it fail) → GREEN (minimal code) → Verify GREEN (all tests pass) → REFACTOR (clean up, stay green) → repeat for the next behaviour.
Write one minimal test showing what should happen.
<Good>
test "retries failed operations 3 times":
attempts = 0
def operation():
attempts += 1
if attempts < 3: raise Error("fail")
return "success"
result = retry_operation(operation)
assert result == "success"
assert attempts == 3
Clear name, tests real behavior, one thing
</Good>
<Bad>
test "retry works":
mock = create_mock()
.fails_twice()
.then_returns("success")
retry_operation(mock)
assert mock.call_count == 3
Vague name, tests mock not code
</Bad>
Requirements:
MANDATORY. Never skip.
Run the project's test command targeting the specific test file.
Confirm:
Test passes? For new behavior, you're testing something that already exists. Fix the test.
Refactoring? Here a passing test is the goal. Before moving any structure, write tests that pass on the current code. They pin the behavior the refactor must keep. Type check and lint are not a pin.
Test errors? Fix error, re-run until it fails correctly.
Write simplest code to pass the test.
<Good>
def retry_operation(fn, max_retries=3):
for i in range(max_retries):
try:
return fn()
except Error:
if i == max_retries - 1: raise
raise Error("unreachable")
Just enough to pass
</Good>
<Bad>
def retry_operation(fn, options=None):
# options: max_retries, backoff_strategy, on_retry_callback
# Configurable backoff: linear, exponential
# YAGNI - all of this
Over-engineered
</Bad>
Don't add features, refactor other code, or "improve" beyond the test.
MANDATORY.
Run the project's test command.
Confirm:
Test fails? Fix code, not test.
Other tests fail? Fix now.
After green only:
Keep tests green. Don't add behavior.
Next failing test for next feature.
| Quality | Good | Bad |
|---------|------|-----|
| Minimal | One thing. "and" in name? Split it. | test "validates email and domain and whitespace" |
| Clear | Name describes behavior | test "test1" |
| Shows intent | Demonstrates desired API | Obscures what code should do |
| Tests behavior | Fails when the behavior breaks, passes when only the internals change | Fails after a rename or an internal refactor that changed no behavior |
| Excuse | Reality |
|--------|---------|
| "Too simple to test" | Simple code breaks. Test takes 30 seconds. |
| "I'll test after" | Tests passing immediately prove nothing. |
| "Tests after achieve same goals" | Tests-after = "what does this do?" Tests-first = "what should this do?" |
| "Already manually tested" | Ad-hoc ≠ systematic. No record, can't re-run. |
| "Deleting X hours is wasteful" | Sunk cost fallacy. Keeping unverified code is technical debt. |
| "Keep as reference, write tests first" | You'll adapt it. That's testing after. Delete means delete. |
| "Need to explore first" | Fine. Throw away exploration, start with TDD. |
| "Test hard = design unclear" | Listen to test. Hard to test = hard to use. |
| "TDD will slow me down" | TDD faster than debugging. Pragmatic = test-first. |
| "Manual test faster" | Manual doesn't prove edge cases. You'll re-test every change. |
| "Existing code has no tests" | You're improving it. Add tests for existing code. |
All of these mean: Delete code. Start over with TDD.
Before marking work complete:
Can't check all boxes? You skipped TDD. Start over.
| Problem | Solution |
|---------|----------|
| Don't know how to test | Write wished-for API. Write assertion first. Ask your human partner. |
| Test too complicated | Design too complicated. Simplify interface. |
| Must mock everything | Code too coupled. Use dependency injection. |
| Test setup huge | Extract helpers. Still complex? Simplify design. |
Bug found? Write failing test reproducing it. Follow TDD cycle. Test proves fix and prevents regression.
Never fix bugs without a test.
Tasks from spec-driven-implementation are already shaped as RED → GREEN → REFACTOR; follow the cycle for each and commit after each phase (test:, feat:, refactor:).
Production code → test exists and failed first
Otherwise → not TDD
No exceptions without your human partner's permission.
Weekly roundup of top Claude Code skills, MCP servers, and AI coding tips.