agentleFS
REPOZYREPOZY/superpowers-optimized/skills/test-driven-development/SKILL.md

test-driven-development

Skill146 starsChanged 7 months agoMITView on GitHub

MUST USE for any behavior change: write failing tests before production code. No exceptions. Triggers on: "TDD", "write tests first", any implementation task, bug fix needing regression tests, behavior changes during execution. Routed by using-superpowers, or invoke directly via /test-driven-development.

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 10 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

  • LLl0k0laDSkill

    git-workflow-and-versioning

    Use when making any code change. Use when committing, branching, resolving conflicts, or when you need to organize work across multiple parallel streams.

    Also in 47 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

  • +3 more from Leodorareluctant259
  • +3 more from LLl0k0laD

The file

Show its rules and text

We split this skill into the rules it gives an agent

22 rules. 0 are common, 16 are distinctive, and 6 are very specific to this project.

  • 0

    Common

    Most of the 178 edited versions we read keep these.

  • 16

    Distinctive

    This author's own choices. Worth a look.

  • 6

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Write failing tests first.

    line 13
  2. Distinctive:

    If code was written first, delete it and restart from a test.

    line 19
  3. Distinctive:

    RED: Write one small failing test for one behavior.

    line 25
  4. Distinctive:

    VERIFY RED: Run the test. Confirm it fails for the expected reason (not a syntax error or import issue).

    line 26
  5. Distinctive:

    GREEN: Write the minimum production code to make the test pass.

    line 27
  6. Very specific:

    VERIFY GREEN: Run the target test plus the suite for the module you changed.

    line 28
  7. Distinctive:

    Before writing the first test, verify the project has a test runner:

    line 37
  8. Very specific:

    Check for test config: jest.config.*, vitest.config.*, pytest.ini, pyproject.toml [tool.pytest], go.mod, Cargo.toml, .rspec, phpunit.xml

    line 39
  9. Very specific:

    Check for test script: npm test, yarn test, make test, or equivalent

    line 40
  10. Distinctive:

    If no test infrastructure exists:

    line 41
  11. Distinctive:

    Ask the user: "No test runner detected.

    line 42
  12. Distinctive:

    If yes: install and configure the minimal test runner.

    line 43
  13. Distinctive:

    If no: note that TDD requires a test runner and proceed only if the user provides an alternative.

    line 44
  14. Distinctive:

    Do not skip this step — a "failing test" that fails because the runner doesn't exist teaches nothing.

    line 46
  15. Distinctive:

    Prefer real behavior checks over mock-only assertions.

    line 81
  16. Distinctive:

    Integration tests: Test real interactions between components (database, API, filesystem).

    line 105
  17. Distinctive:

    Property-based tests: When behavior has invariants (e.g., "sort output is always ordered"), generate random inputs to find edge cases.

    line 107
  18. Distinctive:

    Performance tests: When latency or throughput matters, add benchmarks with clear thresholds.

    line 108
  19. Distinctive:

    Flaky test diagnosis: If a test passes/fails inconsistently, treat it as a bug — find the race condition, timing dependency, or shared …

    line 109
  20. Very specific:

    Use systematic-debugging to find root cause before writing the fix test.

    line 116
  21. Very specific:

    Use verification-before-completion before success claims.

    line 117
  22. Very specific:

    Read testing-anti-patterns.md when introducing heavy mocking.

    line 118

“Common” is measured: kept by at least 6 in 10 of the 178 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

Write failing tests first. Then write minimal code to pass.

Iron Law

No production code before a failing test proves the behavior is missing.

If code was written first, delete it and restart from a test. No exceptions.

This is the hardest rule to follow and the most important. Every rationalization to skip it leads to untested behavior that breaks later.

Cycle

  1. RED: Write one small failing test for one behavior.
  2. VERIFY RED: Run the test. Confirm it fails for the expected reason (not a syntax error or import issue).
  3. GREEN: Write the minimum production code to make the test pass. Nothing more.
  4. VERIFY GREEN: Run the target test plus the suite for the module you changed. Confirm pass. Do not run the whole repo suite on every cycle — that belongs at the end of the task, scoped per verification-before-completion.

    Report every failure the run shows, including ones you did not cause. Scope bounds which command you run; it never bounds what you report. If the module suite goes red on a test your change did not touch, name that test in your report as a pre-existing failure. A red test you watched scroll past and did not mention is a report falsified by omission — and the next person to run the suite inherits it as your bug.

  5. REFACTOR: Improve structure without changing behavior. Tests must stay green.

Repeat per behavior. Never skip VERIFY steps.

Test Infrastructure Check

Before writing the first test, verify the project has a test runner:

  1. Check for test config: jest.config.*, vitest.config.*, pytest.ini, pyproject.toml [tool.pytest], go.mod, Cargo.toml, .rspec, phpunit.xml
  2. Check for test script: npm test, yarn test, make test, or equivalent
  3. If no test infrastructure exists:
    • Ask the user: "No test runner detected. Should I set up [recommended runner for this language/framework]?"
    • If yes: install and configure the minimal test runner. Write one smoke test to confirm it works.
    • If no: note that TDD requires a test runner and proceed only if the user provides an alternative.

Do not skip this step — a "failing test" that fails because the runner doesn't exist teaches nothing.

Right vs Wrong

Wrong — code first:

1. Write the handler function
2. Write tests to verify it works
3. All tests pass on first run ← this means the tests prove nothing

Right — test first:

1. Write test: POST /users returns 201 with valid body
2. Run test → FAILS (handler doesn't exist yet) ← good
3. Write minimal handler to return 201
4. Run test → PASSES ← test proved the behavior was missing, now it works
5. Refactor handler if needed, tests stay green

Rationalization Table — Do Not Skip Tests

TemptationWhy it fails
"This is too simple to test"Simple code has the longest lifespan. It will be changed by someone who doesn't know the intent.
"I'll write tests after"After never comes. And tests written after pass immediately, proving nothing.
"I'm just refactoring, no new behavior"If behavior doesn't change, existing tests must stay green. Run them.
"Tests slow me down"Tests save you from debugging sessions that take 10x longer.
"The type system catches this"Types catch shape errors, not logic errors. Test the logic.
"I need to see the shape of the code first"Spike in a scratch file. Then delete it and TDD the real implementation.

Test Quality Rules

  • One behavior per test.
  • Clear behavior-oriented test names (e.g., test_expired_token_returns_401).
  • Prefer real behavior checks over mock-only assertions.
  • Cover edge and error paths for changed behavior.
  • A test that has never been seen failing is not a test — it's a wish.

Anti-Patterns

  • Writing tests after implementation.
  • Adding multiple features before rerunning tests.
  • Accepting passing tests that never failed first.
  • Fixing bugs without a regression test.
  • Testing mock behavior instead of real behavior.

Completion Checklist

  • Every changed behavior has a test.
  • Each new test was observed failing before implementation.
  • Changed tests pass.
  • The suite covering the changed module passes (scope per verification-before-completion).
  • Any failure in that run which this change did not cause is named explicitly in the report as pre-existing — never silently passed over.

Advanced Test Strategy

For complex, high-risk, or hard-to-test behavior, go beyond basic unit tests while still following RED-GREEN-REFACTOR:

  • Integration tests: Test real interactions between components (database, API, filesystem). Prefer real dependencies over mocks.
  • E2E tests: For user-facing flows, verify the full path from input to output.
  • Property-based tests: When behavior has invariants (e.g., "sort output is always ordered"), generate random inputs to find edge cases.
  • Performance tests: When latency or throughput matters, add benchmarks with clear thresholds.
  • Flaky test diagnosis: If a test passes/fails inconsistently, treat it as a bug — find the race condition, timing dependency, or shared state causing it.
  • Coverage strategy: Focus coverage on behavior boundaries and error paths, not line counts. 80% meaningful coverage beats 100% trivial coverage.

Choose appropriate frameworks and libraries for the current stack. Write tests that are fast, deterministic, and maintainable.

Related

  • Use systematic-debugging to find root cause before writing the fix test.
  • Use verification-before-completion before success claims.
  • Read testing-anti-patterns.md when introducing heavy mocking.

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.