agentleFS
int2t05int2t05/engineering-skills/skills/06-test/tdd/SKILL.md

tdd

Skill3 starsChanged 4 months agoMITView on GitHub

Use when implementing any feature or bugfix, before writing implementation code — red-green-refactor loop, one vertical slice at a time. Triggers on "tdd", "test-driven", "red green refactor", "测试驱动开发", "红绿重构", "测试驱动". Not for spec-driven slice implementation (use implement — it drives TDD within each slice) or generating tests for existing code (use test-generation).

193 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use make-bot-ui, Poteto Mode 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.
  • eryzerzSkill

    make-bot-ui

    Use when building a custom UI (page, dashboard, buttons) that should wake a Grok Bot over a webhook, when the user must provide a webhook sender key, or when exposing that UI on Tailscale.

    Also in 8 projects that use this

  • jtarorehSkill

    Poteto Mode

    poteto's agent style for concise, detailed responses, deliberate subagents, unslopped prose, simple code, and verified work. Use for poteto, /poteto-mode, or requests to work in this style.

    Also in 5 projects that use this

  • risadamsSkill

    which-skill

    Router over this pack's skills and flows. Ask it "which skill fits X" when you don't remember what's available.

    Also in 7 projects that use this

  • TheOnlyFusionCubeSkill

    principle-attack-the-premise

    Inventory who actually owns or exhibits the imbalance, then challenge the shared premise before writing another patch. Use when two or more fixes that share one premise have failed the same gate.

    Also in 11 projects that use this

  • TheOnlyFusionCubeSkill

    principle-test-behavior-not-implementation

    Call the system the way its consumer does and assert meaningful observable output; avoid mocks or assertions that only mirror internal calls. Use when when writing or evaluating tests.

    Also in 11 projects that use this

  • shreyT19Skill

    principle-laziness-protocol

    Apply when refactoring, evaluating diff size, or tempted to add abstractions, layers, or signal threading. Bias toward deletion and the smallest change that solves the problem.

    Also in 22 projects that use this

The file

We split this skill into the rules it gives an agent

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

  • 0

    Common

    Most of the 177 edited versions we read keep these.

  • 8

    Distinctive

    This author's own choices. Worth a look.

  • 0

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Write the failing test first.

    line 8
  2. Distinctive:

    Iron law: No production code without a failing test first.

    line 11
  3. Distinctive:

    Run the focused test command.

    line 53
  4. Distinctive:

    Run the focused test command, then the full suite.

    line 68
  5. Distinctive:

    No other tests broke (if they did, fix now — don't skip)

    line 71
  6. Distinctive:

    Only while green: extract helpers, improve names, remove duplication.

    line 76
  7. Distinctive:

    Commit the test and implementation together as one vertical slice.

    line 82
  8. Distinctive:

    Don't start by fixing. Write a test that reproduces the bug (RED confirms it exists), then fix (GREEN proves the fix works).

    line 87

“Common” is measured: kept by at least 6 in 10 of the 177 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 the failing test first. Watch it fail. Write minimal code to pass. Refactor. A test that passes immediately proves nothing — you never saw it catch a bug.

Iron law: No production code without a failing test first. If you wrote code before the test, delete it and start over. "Keep as reference" is testing-after in disguise — delete means delete.

When to use

  • Implementing any new feature or behavior
  • Fixing a bug (reproduce it with a test first — the Prove-It Pattern)
  • Refactoring or changing existing behavior
  • Triggers on "tdd", "test-driven", "red green refactor", "测试驱动开发", "红绿重构", "测试驱动"

Not for: generating tests for already-written code (use test-generation); have a spec and want slice-by-slice feature implementation (use implement — it drives TDD within each slice).

Exceptions (confirm with the user): throwaway prototypes, generated code, pure configuration changes with no behavioral impact — for these, confirm with the user before skipping TDD rather than defaulting either way.

Steps

0. Discover the stack first

The cycle is universal; the commands are not. Before the first test, find how this repo tests: read package.json / pyproject.toml / Cargo.toml / pom.xml / go.mod, check for ./gradlew, Makefile, CI workflows, and existing test-file naming. Never assume npm test — use the repo's own command for every RED, GREEN, and final verification.

1. RED — write one failing test

One behavior, one test, one vertical slice (tracer bullet that responds to what the last cycle taught you). Write the test you wish existed — it describes the desired API, not the implementation. Name it as a specification ("rejects empty email", not "test1").

Agree the seam (public interface under test) before writing. No test at an unconfirmed seam — agreeing seams up front puts testing effort on critical paths instead of every edge case. Use real code over mocks; if you must double a dependency, use the simplest double that works (Real > Fake > Stub > Mock — see references/test-strategy.md). Mocks isolate boundaries, not the thing being tested.

2. Verify RED — watch it fail

Run the focused test command. Confirm:

  • It fails (not errors — errors mean fix the setup and re-run)
  • It fails for the right reason (feature missing, not a typo)
  • A test that passes immediately means you're testing existing behavior — fix the test

3. GREEN — write minimal code

The simplest code that passes the test. No speculative features, no "flexibility", no refactoring adjacent code. YAGNI. Don't add test-only methods (destroy(), reset()) to production classes — put cleanup in test utilities.

4. Verify GREEN — watch it pass

Run the focused test command, then the full suite. Confirm:

  • The new test passes
  • No other tests broke (if they did, fix now — don't skip)
  • Output is pristine (no warnings, no skipped tests)

5. REFACTOR — clean up

Only while green: extract helpers, improve names, remove duplication. Run tests after every refactor step. Don't add behavior. Refactoring belongs to the review stage, not the red → green implementation cycle.

6. Commit

Commit the test and implementation together as one vertical slice. Then start the next failing test.

Bug fixes — the Prove-It Pattern

Don't start by fixing. Write a test that reproduces the bug (RED confirms it exists), then fix (GREEN proves the fix works). The test stays as a regression guard. Never fix a bug without a reproduction test.

Verify

  • Every new behavior has a test that failed first
  • Full suite passes with the repo's own test command
  • Bug fixes include a reproduction test that failed before the fix
  • Test names describe behavior, not implementation
  • No tests skipped or disabled; no test-only methods in production code

References

  • ${CLAUDE_PLUGIN_ROOT}/references/engineering-principles.md — discipline every skill shares
  • references/test-strategy.md — test pyramid, test-double hierarchy (Real > Fake > Stub > Mock), DAMP over DRY
  • references/testing-anti-patterns.md — mock misuse, test-only methods, partial mocks, gate functions
  • references/mocking.md — when to mock, designing for mockability
  • references/good-tests.md — good vs bad test examples, tautological tests

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.