agentleFS
dvy1987dvy1987/agent-loom/.agents/skills/test-driven-development/SKILL.md

test-driven-development

Skill4 starsChanged 3 months agoMITView on GitHub

Apply the Red-Green-Refactor cycle to software development. Load when the user asks to write code using TDD, create unit tests, implement a feature with test coverage, refactor code, or ensure software quality through automated testing. Also triggers on "test-driven development", "write tests first", "TDD this feature", "Red-Green-Refactor", "ensure 100% test coverage", or any request to build software with a test-first approach. Supports unit, integration, and end-to-end testing strategies.

190 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use chinese-code-review, chinese-commit-conventions and 7 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • Leodorareluctant259Skill

    chinese-code-review

    中文代码审查规范——在保持专业严谨的同时,用符合国内团队文化的方式给出有效反馈

    Also in 8 projects that use this

  • Leodorareluctant259Skill

    chinese-commit-conventions

    中文 Git 提交规范 — 适配国内团队的 commit message 规范和 changelog 自动化

    Also in 8 projects that use this

  • obraSkill

    diagnosing-superpowers

    Use when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.

    Also in 19 projects that use this

  • LLl0k0laDSkill

    using-agent-skills

    Use when starting a session or when you need to discover which skill applies to the current task. This is the meta-skill that governs how all other skills are discovered and invoked.

    Also in 39 projects that use this

  • MrCipherSmithSkill

    constraint-driven-development

    Use when a project needs a persistent, measurable quality bar — starting a project without documented standards, 'set up constraints', or when coverage/perf/a11y thresholds get re-debated per-PR. Produces CONSTRAINTS.md with enforceable numbers, ratchets, and a guard against silent weakening. NOT for throwaway prototypes or a one-off CI setup.

    Also in 15 projects that use this

  • LLl0k0laDSkill

    debugging-and-error-recovery

    Use when tests fail, builds break, behavior doesn't match expectations, or you encounter any unexpected error. Use when you need a systematic approach to finding and fixing the root cause rather than guessing.

    Also in 46 projects that use this

  • +3 more from Leodorareluctant259

The file

Show its rules and text

We split this skill into the rules it gives an agent

22 rules. 0 are common, 14 are distinctive, and 8 are very specific to this project.

  • 0

    Common

    Most of the 179 edited versions we read keep these.

  • 14

    Distinctive

    This author's own choices. Worth a look.

  • 8

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Never write production code without a failing test first (Red phase).

    line 30
  2. Distinctive:

    Never write more code than necessary to pass the current failing test (Green phase).

    line 31
  3. Distinctive:

    Never skip the Refactor phase — clean up code only when tests are passing.

    line 32
  4. Distinctive:

    Never compromise on test clarity — tests are documentation.

    line 33
  5. Very specific:

    Read the PRD (docs/prd/) or implementation plan (docs/plans/).

    line 41
  6. Very specific:

    Write a test that describes the expected behavior.

    line 45
  7. Very specific:

    Run the test and confirm it fails for the right reason (e.g., ReferenceError or AssertionError).

    line 46
  8. Distinctive:

    Stop. Do not write any production code yet.

    line 47
  9. Distinctive:

    Write just enough code to make the test pass.

    line 50
  10. Distinctive:

    Don't worry about performance or elegance yet — focus on "Green." Run the test and confirm it passes.

    line 51
  11. Distinctive:

    Run the test and confirm it passes.

    line 52
  12. Distinctive:

    Run the tests again to ensure no regressions were introduced.

    line 56
  13. Very specific:

    Ensure all tests in the suite pass.

    line 60
  14. Very specific:

    When UI or browser E2E is in scope, pair with browser-testing-with-devtools after unit/integration tests pass.

    line 62
  15. Distinctive:

    If a test requires >10 lines of setup, the code under test has too many dependencies.

    line 78
  16. Very specific:

    Never assert against a mock's own behavior (it always "passes"), and never add test-only methods/hooks to production classes — see …

    line 79
  17. Very specific:

    Run: NameError: name 'calculate_debt_interest' is not defined — correct failure.

    line 96
  18. Distinctive:

    Run: ✓ Both tests pass.

    line 125
  19. Distinctive:

    Test passes on first run (may not test what you think)

    line 164
  20. Distinctive:

    Test names that don't describe behavior

    line 166
  21. Very specific:

    Read references/examples.md for full worked examples.

    line 177
  22. Distinctive:

    After completing, always report:

    line 186

“Common” is measured: kept by at least 6 in 10 of the 179 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Test-Driven Development (TDD)

You are a Senior Software Engineer with a passion for quality. You follow the Red-Green-Refactor cycle strictly. You never write production code before a failing test exists, and you never refactor without a passing test suite.

Hard Rules

Never write production code without a failing test first (Red phase). Never write more code than necessary to pass the current failing test (Green phase). Never skip the Refactor phase — clean up code only when tests are passing. Never compromise on test clarity — tests are documentation. Code written before its test existed must be deleted, not retrofitted with a test after the fact — start over from Red.


Workflow

Step 1 — Define the Requirement

Read the PRD (docs/prd/) or implementation plan (docs/plans/). Identify the smallest, testable unit of functionality.

Step 2 — Red Phase (Write a Failing Test)

Write a test that describes the expected behavior. For bug fixes, use the Prove-It Pattern — full protocol in references/tdd-patterns.md (repro → fix → regression guard). Run the test and confirm it fails for the right reason (e.g., ReferenceError or AssertionError). Stop. Do not write any production code yet.

Step 3 — Green Phase (Write Minimal Code)

Write just enough code to make the test pass. Don't worry about performance or elegance yet — focus on "Green." Run the test and confirm it passes.

Step 4 — Refactor Phase (Clean Up)

With the test passing, refactor the code for readability, performance, and structure. Run the tests again to ensure no regressions were introduced. Repeat Steps 2–4 for the next small unit of functionality.

Step 5 — Verify and Save

Ensure all tests in the suite pass. Save the tests to tests/ and the code to src/ (or project equivalent). When UI or browser E2E is in scope, pair with browser-testing-with-devtools after unit/integration tests pass.

Append to docs/skill-outputs/SKILL-OUTPUTS.md:

| YYYY-MM-DD HH:MM | test-driven-development | [test path] | TDD: <feature> |

Tell the user:

"TDD cycle complete for <feature>. Tests saved to [test path]. Logged in docs/skill-outputs/SKILL-OUTPUTS.md."


Gotchas

  • Agents skip Red — they jump straight to writing code and tests together. Enforce the discipline: write the test FIRST, run it, see it FAIL, only then write code. The failure message confirms you are testing the right thing.
  • "Test the framework" is the #1 agent mistake. Testing that FastAPI returns 200 for a valid route tests FastAPI, not your code. Test the business logic the route calls, not the HTTP plumbing.
  • Agents write one giant test per feature instead of many small tests. Each test should verify exactly one behavior. If a test name contains "and" ("test_login_and_redirect_and_set_cookie"), split it into three tests.
  • If a test requires >10 lines of setup, the code under test has too many dependencies. This is TDD's most valuable signal — hard-to-test code needs architectural refactoring, not more mocking.
  • Never assert against a mock's own behavior (it always "passes"), and never add test-only methods/hooks to production classes — see references/tdd-patterns.md Anti-patterns table.

Example

<examples> <example> <input>TDD a function that calculates the "interest rate" of a technical debt item based on its blast radius and frequency of encounters.</input> <output> **Target Feature:** `calculate_debt_interest(blast_radius: int, encounter_frequency: int) -> str`

Red Phase — Test 1: Basic classification

def test_high_interest_when_high_blast_and_frequent():
    assert calculate_debt_interest(blast_radius=8, encounter_frequency=5) == "high"

Run: NameError: name 'calculate_debt_interest' is not defined — correct failure.

Green Phase — Minimal implementation

def calculate_debt_interest(blast_radius: int, encounter_frequency: int) -> str:
    score = blast_radius * encounter_frequency
    if score >= 20:
        return "high"
    return "low"

Run: ✓ Test passes.

Red Phase — Test 2: Medium classification

def test_medium_interest_when_moderate_score():
    assert calculate_debt_interest(blast_radius=3, encounter_frequency=3) == "medium"

Run: AssertionError: 'low' != 'medium' — correct failure.

Green Phase — Add medium tier

def calculate_debt_interest(blast_radius: int, encounter_frequency: int) -> str:
    score = blast_radius * encounter_frequency
    if score >= 20:
        return "high"
    if score >= 8:
        return "medium"
    return "low"

Run: ✓ Both tests pass.

Refactor Phase: Extracted threshold constants, added docstring. All tests still green.

TDD session complete: calculate_debt_interest Tests written: 2 (+ 1 edge case for score=0) Code coverage achieved: 100% Refactorings performed: 1 (extract constants) Status: Green (All tests passing) Ready for: code review </output> </example> </examples>


Output Format

TDD Session Report:

  1. Target Feature (What we are building).
  2. Test Case(s) (Description of the tests written).
  3. Pass/Fail Status (Final result of the suite).
  4. Refactorings Applied (What was cleaned up).

Common Rationalizations

ExcuseReality
"I'll write tests after it works"Tests written after code test implementation, not behavior.
"Too simple to test"Simple code grows; tests document expected behavior.
"I tested it manually"Manual checks don't guard the next change.
"Let me run tests again to be sure"Re-run only after code changes — identical re-runs add nothing.
"I already wrote this, I'll just add a test for it"Delete it and rewrite from Red — a test written against existing code confirms the code, not the contract.

Red Flags

  • Production code with no corresponding test
  • Test passes on first run (may not test what you think)
  • Bug fix without a reproduction test
  • Test names that don't describe behavior

Verification

  • Every new behavior has a test; bug fixes include a failing-then-passing repro test
  • Full suite passes: [project test command]
  • Test names read as specifications
  • No tests skipped or disabled to green the suite

Read references/examples.md for full worked examples.

Prune Log

Last pruned: 2026-07-09

  • Added delete-not-retrofit enforcement + mock/test-only-method anti-pattern citation (agent-loom Phase 4, obra/superpowers)

Impact Report

After completing, always report:

TDD session complete: [feature name]
Tests written: [N]
Code coverage achieved: [N%]
Refactorings performed: [N]
Status: Green (All tests passing)
Ready for: code review / integration

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.