tdd-canon
Skill4 starsChanged 59 days agoMITView on GitHub
Practice Kent Beck's Canon Test-Driven Development with strict Red-Green-Refactor discipline. Use this skill whenever the user mentions TDD, test-driven development, "write tests first", "red green refactor", "test list", "failing test first", "make the test pass", or asks to build any feature using a test-first approach. Also activate when the user says "let's TDD this", "drive this with tests", or references Canon TDD. This skill MUST be used for any test-first workflow — do not attempt TDD without it.
In this repository15 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- ac-quality-reviewSkill
- beadsSkill
- create-beadSkill
- freshness-triageSkill
- plan-to-beadsSkill
- playwright-cliSkill
- reaperSkill
- reviewSkill
- verify-acceptanceSkill
- wishSkill
- create-beadSkill
- plan-to-beadsSkill
- wishSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
48 rules. About 0 are common, 39 are distinctive, and 9 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈39
Distinctive · estimate
This author's own choices. Worth a look.
9
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 32
One test at a time: Never write a second test before the first one passes.
- Distinctive: line 33
Never write multiple tests speculatively "to save time." Each test shapes the implementation, and the second test is influenced by the code …
- Distinctive: line 52
Before starting, determine the project's test framework and runner:
- Very specific: line 54
Look for config files: vitest.config.*, jest.config.*, pytest.ini, pyproject.toml (pytest section), Cargo.toml (Rust), go.test, .mocharc.*, …
- Very specific: line 57
Look for existing test files to understand naming conventions (.test.ts, .spec.ts, test_*.py, *_test.go, *_test.cpp, etc.).
- Distinctive: line 61
If no framework exists, ask the user which framework to set up.
- Very specific: line 62
If a CONTEXT.md exists at the repo root (or per-context, located via a root CONTEXT-MAP.md), read it and use its canonical terms in test …
- Very specific: line 65
Check docs/adr/ for decisions in the area you're touching before the test list commits to an interface.
- Distinctive: line 72
When the user describes a feature, behavior change, or bug fix, your FIRST action is to produce a Test List.
- Distinctive: line 101
Do NOT sneak implementation decisions into the list.
- Distinctive: line 103
Keep items small enough that each becomes exactly one test.
- Distinctive: line 108
After presenting the test list, proceed immediately to Phase 2 with the first item.
- Distinctive: line 116
Create (or add to) the appropriate test file following project conventions.
- Distinctive: line 122
Use the simplest possible assertion that verifies the behavior
- Distinctive: line 124
Import from the module path where the production code WILL live
- Distinctive: line 128
Do NOT write implementation code.
- Distinctive: line 131
Do NOT write more than one test.
- Very specific: line 132
Do NOT write a test without meaningful assertions.
- Distinctive: line 134
Do NOT design the implementation.
- Distinctive: line 140
Run the test suite. Confirm the new test FAILS and all previous tests still PASS.
- Distinctive: line 149
If the test passes without implementation changes, something is wrong.
- Distinctive: line 151
Do not proceed to Green with a test that did not go Red.
- Distinctive: line 155
Write the MINIMUM code to make the failing test pass.
- Very specific: line 159
Minimum means minimum: If the test expects return 0 for an empty case, literally return 0.
- Distinctive: line 167
Create production files as needed: Put them where the test's import statements expect them.
- Very specific: line 174
Do NOT delete, comment out, or skip (xit, test.skip, @pytest.mark.skip) any test or assertion.
- Very specific: line 177
Do NOT weaken assertions (e.g., changing toBe(42) to toBeTruthy(), or changing assertEqual to assertIsNotNone).
- Distinctive: line 180
Do NOT modify a previously passing test to make it accommodate new code.
- Very specific: line 183
Do NOT return hardcoded true/false to bypass validation logic that a test is checking.
- Distinctive: line 187
Do NOT copy computed output into expected values.
- Distinctive: line 190
Do NOT refactor during Green.
- Distinctive: line 192
Do NOT implement scenarios from the Test List that have no test yet.
- Distinctive: line 198
Run the test suite. Confirm ALL tests pass.
- Distinctive: line 199
If there were N tests before Green, there must be at least N tests after.
- Distinctive: line 210
ONLY after Green, with all tests passing, you MAY refactor.
- Distinctive: line 214
Remove duplication (but "duplication is a hint, not a command")
- Distinctive: line 230
Run tests AFTER every refactoring step.
- Distinctive: line 231
Keep refactoring steps small.
- Distinctive: line 232
Run tests between each.
- Distinctive: line 233
If refactoring reveals a new scenario, add it to the Test List.
- Distinctive: line 238
Run the test suite. Confirm ALL tests still pass.
- Distinctive: line 248
Check off the completed item in the Test List.
- Distinctive: line 249
If the Test List still has unchecked items, return to Phase 2 with the next one.
- Distinctive: line 250
If new items were added during the cycle, present the updated list.
- Distinctive: line 253
When the list is empty, announce:
- Distinctive: line 282
If the user asks you to:
- Distinctive: line 298
If the user INSISTS after your explanation, comply — they are the user.
- Distinctive: line 349
Use whatever matches the project.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Canon TDD — Kent Beck's Discipline
You are practicing Kent Beck's Canon TDD. This is not "write some tests then code." This is a strict, phased discipline where each step has clear boundaries that must never bleed into the next.
Your mantra: Red. Green. Refactor. Nothing else.
Core Principles
These are not suggestions. They are the load-bearing walls of the process. When you feel the urge to cut a corner, re-read the principle you're about to violate and understand why it exists.
- Interface before implementation. Tests drive the API surface (logical design). Implementation decisions (physical design) come later, during Green and Refactor. This separation exists because mixing them creates coupled, brittle tests that break when internals change — which is the opposite of what tests are for.
- One test at a time. Never write a second test before the first one passes. Never write multiple tests speculatively "to save time." Each test shapes the implementation, and the second test is influenced by the code that emerged from the first. Writing tests in batches robs you of this feedback loop.
- Phases never overlap. Writing a test (Red) is a different mental act than making it pass (Green), which is a different act than improving design (Refactor). Mixing them is the most common way to corrupt the process — it creates ambiguity about whether a failure is from new test logic or a refactoring mistake.
- The test list is living. New scenarios discovered during any phase get added to the list — they do not get implemented immediately. This keeps your focus on the current cycle and prevents scope creep within a single Red-Green-Refactor.
- Behavioral focus. Think in concrete scenarios (given X, when Y, then Z), not in implementation blueprints. Good test list items describe what the system does, not how it does it.
Phase 0: Detect Test Framework
Before starting, determine the project's test framework and runner:
- Look for config files:
vitest.config.*,jest.config.*,pytest.ini,pyproject.toml(pytest section),Cargo.toml(Rust),go.test,.mocharc.*,phpunit.xml,CMakeLists.txt(Google Test/Catch2), or similar. - Look for existing test files to understand naming conventions (
.test.ts,.spec.ts,test_*.py,*_test.go,*_test.cpp, etc.). - Determine the test run command (
npx vitest run,npm test,pytest,go test,cargo test,ctest, etc.). - If no framework exists, ask the user which framework to set up. Do not assume.
- If a
CONTEXT.mdexists at the repo root (or per-context, located via a rootCONTEXT-MAP.md), read it and use its canonical terms in test names, fixtures, and scenario descriptions — never a term the glossary lists under Avoid. Checkdocs/adr/for decisions in the area you're touching before the test list commits to an interface.
Store this context mentally. You will need the run command throughout.
Phase 1: Test List
When the user describes a feature, behavior change, or bug fix, your FIRST action is to produce a Test List. Do NOT write any code yet.
How to build the Test List
Analyze the desired behavioral change and list concrete scenarios:
- Happy path cases — the basic expected behaviors
- Edge cases — boundaries, empty inputs, minimums, maximums
- Failure modes — invalid inputs, missing data, permission errors
- Existing behavior that must not break — regression scenarios
Test List format
Present the list to the user as a numbered markdown checklist:
### Test List
- [ ] 1. [Scenario description in plain English]
- [ ] 2. [Scenario description in plain English]
- [ ] 3. ...Test List rules
- Each item describes a BEHAVIOR, not an implementation detail. Good: "returns zero when the cart is empty" Bad: "test the calculateTotal method"
- Do NOT sneak implementation decisions into the list. No mention of specific data structures, algorithms, or internal methods unless they ARE the interface.
- Keep items small enough that each becomes exactly one test.
- Order matters. Sequence from simplest/most fundamental to most complex. The first test should be the one that forces you to create the minimum skeleton. Beck: "Test ordering affects the final code structure."
After presenting the test list, proceed immediately to Phase 2 with the first item.
Phase 2: Red — Write Exactly One Failing Test
Pick the FIRST unchecked item from the Test List.
Write the test
- Create (or add to) the appropriate test file following project conventions.
- The test MUST have:
- Arrange: Concrete setup with real values (not vague placeholders)
- Act: A single invocation of the interface being designed
- Assert: Meaningful assertions about expected behavior
- The test SHOULD:
- Use the simplest possible assertion that verifies the behavior
- Name itself after the scenario, not the implementation
- Import from the module path where the production code WILL live
Prohibitions during Red
- Do NOT write implementation code. Not even stubs. Not even empty files. The test must fail because the code does not exist yet (or does not handle this case). The compile/import error IS the first Red.
- Do NOT write more than one test.
- Do NOT write a test without meaningful assertions.
expect(true).toBe(true)is not TDD, it is theater. - Do NOT design the implementation. You are designing the INTERFACE — what the caller sees. Beck: "Chill. There will be plenty of time to decide how the internals will look later."
Verify Red
Run the test suite. Confirm the new test FAILS and all previous tests still PASS.
Report:
RED: [test name] fails as expected.
Reason: [why it fails — import error, function not found, assertion mismatch, etc.]
Previous tests: all passing.If the test passes without implementation changes, something is wrong. Either the test is not testing new behavior, or the behavior already exists. Investigate. Do not proceed to Green with a test that did not go Red.
Phase 3: Green — Make It Pass (Minimally)
Write the MINIMUM code to make the failing test pass.
Rules for Green
- Minimum means minimum. If the test expects
return 0for an empty case, literally return 0. Do not build the general solution yet. Beck calls this "obvious implementation" for trivial cases and "fake it" for non-trivial ones. Both are valid. Over-engineering is not. - All tests must pass. The new test AND every previous test. If a previous test breaks, fix it without deleting its assertions. If you cannot fix it without a significant design change, add that scenario to the Test List and back out.
- Create production files as needed. Put them where the test's import statements expect them.
Prohibitions during Green
- Do NOT cheat to make tests pass. This is the single most important rule. The
temptation to take shortcuts is strong — resist it completely. Specifically:
- Do NOT delete, comment out, or skip (
xit,test.skip,@pytest.mark.skip) any test or assertion. Every assertion that existed before Green must still exist and still assert the same thing. - Do NOT weaken assertions (e.g., changing
toBe(42)totoBeTruthy(), or changingassertEqualtoassertIsNotNone). The assertion was written in Red for a reason — it encodes the expected behavior. - Do NOT modify a previously passing test to make it accommodate new code. If new code breaks an old test, the new code is wrong — fix the implementation, not the test.
- Do NOT return hardcoded
true/falseto bypass validation logic that a test is checking. "Fake it" means returning a simple constant for the FIRST test to get the skeleton in place — it does NOT mean returningtrueto skip implementing real logic when the test expects real behavior. - Do NOT copy computed output into expected values. Run the code, see what it produces, then paste that into the assertion — this defeats the purpose of TDD. Expected values come from understanding the behavior, not from running the code.
- Do NOT delete, comment out, or skip (
- Do NOT refactor during Green. If you see duplication, ugly code, or a better structure — note it, but do not act on it. That is Refactor's job.
- Do NOT implement scenarios from the Test List that have no test yet. If you think "while I'm here I might as well handle the null case" — stop. Add it to the list if it is not there. Move on.
Verify Green
Run the test suite. Confirm ALL tests pass. Verify the test count has not decreased. If there were N tests before Green, there must be at least N tests after. If the count dropped, you deleted or skipped a test — undo and try again.
Report:
GREEN: All tests passing ([N] total, was [M] before).
Implementation: [1-2 sentence summary of what you wrote]Phase 4: Refactor — Improve Design (Optional)
ONLY after Green, with all tests passing, you MAY refactor.
What refactoring means here
- Remove duplication (but "duplication is a hint, not a command")
- Improve naming
- Extract functions or methods for clarity
- Simplify logic
- Improve performance IF the test list includes performance scenarios
What refactoring does NOT mean
- Adding new behavior (that requires a new test first)
- Changing the public interface (that could break existing tests)
- Prematurely abstracting for hypothetical future requirements
- Rewriting working code because you "don't like" the fake-it approach (the next test will force generalization naturally)
Rules for Refactor
- Run tests AFTER every refactoring step. If tests break, undo immediately.
- Keep refactoring steps small. One rename. One extraction. One simplification. Run tests between each.
- If refactoring reveals a new scenario, add it to the Test List. Do not implement it now.
Verify Refactor
Run the test suite. Confirm ALL tests still pass.
Report:
REFACTOR: All tests still passing.
Changes: [what you improved, or "No refactoring needed — code is clean."]Phase 5: Repeat
- Check off the completed item in the Test List.
- If the Test List still has unchecked items, return to Phase 2 with the next one.
- If new items were added during the cycle, present the updated list.
- Continue until the Test List is empty.
When the list is empty, announce:
TDD COMPLETE: All [N] scenarios tested and passing.
Test list is empty. All behavioral requirements are covered.State Tracking
Throughout the TDD session, display a status block when transitioning between phases. This makes the current state visible and phase-skipping obvious:
--- TDD Status ---
Phase: [Red | Green | Refactor | Complete]
Test List: [X/Y completed]
Current test: [name or "none"]
All tests passing: [yes/no]
------------------Autonomous Operation
This workflow runs end-to-end without pausing for human confirmation between phases. Build the test list and immediately begin the first Red phase. Run through each Red-Green-Refactor cycle continuously. Continue through the entire test list until complete. The status block at each phase transition lets the user follow along.
Handling Requests That Break Discipline
If the user asks you to:
- "Just write the implementation" — Remind them that in Canon TDD, the implementation emerges from the tests. This matters because writing implementation first means the tests end up confirming what you wrote rather than specifying what you need. Offer to work through the test list quickly with tight cycles.
- "Write all the tests first" — Explain that batch-testing loses the feedback loop that makes TDD valuable. Each test shapes the implementation, and the next test is informed by that shape. Offer to keep cycles fast so it doesn't feel slow.
- "Skip the test list" — The test list is how you avoid wandering and missing scenarios. Without it, you'll either over-build or under-build. Offer to make it brief — even 3-4 items is better than none.
- "This is taking too long" — Acknowledge the concern. Offer shorter test lists and tighter cycles. But do not collapse Red-Green-Refactor into a single step — that eliminates the phase separation that catches mistakes.
If the user INSISTS after your explanation, comply — they are the user. But note that you are leaving Canon TDD discipline.
Framework Examples
Adapt syntax to whatever test framework the project uses. The methodology is identical regardless of language or framework.
TypeScript (Vitest/Jest):
describe('CartTotal', () => {
it('returns zero when the cart is empty', () => {
const cart = createCart();
expect(cart.total()).toBe(0);
});
});Python (pytest):
def test_cart_total_returns_zero_when_empty():
cart = create_cart()
assert cart.total() == 0Go:
func TestCartTotal_ReturnsZeroWhenEmpty(t *testing.T) {
cart := NewCart()
if got := cart.Total(); got != 0 {
t.Errorf("Total() = %d, want 0", got)
}
}C++ (Google Test):
TEST(CartTotalTest, ReturnsZeroWhenEmpty) {
Cart cart;
EXPECT_EQ(cart.total(), 0);
}C++ (Catch2):
TEST_CASE("Cart total returns zero when empty", "[cart]") {
Cart cart;
REQUIRE(cart.total() == 0);
}Use whatever matches the project. Do not force a framework.
Common TDD Anti-Patterns to Resist
| Anti-Pattern | What It Looks Like | What To Do Instead |
| Test-after | Writing implementation then tests | Always Red first |
| Assertion-free tests | Tests that call code but check nothing | Every test needs a real assertion |
| Multiple tests at once | Writing 5 tests before making any pass | One at a time, always |
| Gold-plating in Green | Building general solution for first test | Minimum to pass, generalize later |
| Refactoring in Red | "Cleaning up" while writing the test | Write the test, stop, run it |
| Refactoring in Green | Improving design while making it pass | Make it pass, then refactor separately |
| Implementation leakage | Test knows about internals it shouldn't | Test the interface, not the guts |
| Test-list skipping | Jumping straight to writing tests | Always start with behavioral analysis |
| Copy-paste expected values | Running code, copying output into assertion | Expected values come from understanding the behavior |
| Deleting tests to pass | Removing or skipping a failing test | Fix the implementation, never the test |
| Weakening assertions | Changing toBe(42) to toBeTruthy() | Keep the original assertion; it encodes the spec |
| Return true to cheat | return true to bypass real logic | Implement the actual behavior the test demands |
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

