agentleFS
rkalievrkaliev/eng-kit/skills/test-driven-development/SKILL.md

test-driven-development

Skill1 starsChanged 13 days agoMITView on GitHub

Use when implementing any feature, bugfix, refactor or behavior change, before writing the implementation code

191 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

  • steven123397Skill

    accessibility-engineering

    Audits existing interfaces for WCAG 2.2 AA conformance and remediates the violations found. Use when auditing a page or component for accessibility, running axe-core or pa11y, triaging a11y violations, or checking screen reader and contrast issues before shipping.

    Also in 4 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 46 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 21 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 54 projects that use this

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

The file

We split this skill into the rules it gives an agent

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

  • 0

    Common

    Most of the 182 edited versions we read keep these.

  • 3

    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:

    If you didn't watch the test fail, you don't know that it tests the right thing.

    line 13
  2. Distinctive:

    Verify RED. Mandatory: Run it. It must *fail* (not error) with the expected message, *because the feature is missing*.

    line 20
  3. Distinctive:

    GREEN: Write the simplest code that passes.

    line 23

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

NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST

If you didn't watch the test fail, you don't know that it tests the right thing. Following the letter of this rule is the spirit of it.

Exceptions only with the user's explicit agreement: throwaway spikes, generated code, pure configuration. Legacy code without tests is not an exception. Use changing-legacy-code and pin current behavior first.

The cycle

  1. RED. Write one minimal test for one behavior. Give it a clear name, use real code, and mock only true boundaries (network, clock, hardware, payment provider). Take the expected values from the spec or criterion, never from running the code. Before you write it, name the production change that would make it fail.
  2. Verify RED. Mandatory. Run it. It must fail (not error) with the expected message, because the feature is missing.
    • Passes immediately? You're testing existing behavior. Fix the test. (A characterization test that pins legacy behavior passes by design; see changing-legacy-code.)
    • Errors? Fix the error and re-run until it fails for the right reason. A missing module or an undefined symbol is an error, not RED: add a stub that returns a wrong value, then re-run.
  3. GREEN. Write the simplest code that passes. No extra options, no speculative generality, no drive-by refactors.
  4. Verify GREEN. Mandatory. Run the test, then the project's full test command. The output must be clean: no new warnings or errors. If another test fails, fix it now or report it by name. A red test you saw scroll past and didn't mention falsifies your report.
  5. REFACTOR, only while green: remove duplication, improve names. Re-run. Add no behavior.

Code written before its test is deleted and rewritten from the test. Don't keep it as a "reference": you'll adapt it, which is testing after.

Tests stay honest

  • Never weaken a test to get green. That includes editing an assertion to match output, deleting a test, adding .skip/.only/xit, loosening a tolerance, or catching the error in the test. What may change, and with whose agreement, is in references/test-standard.md ("Changing tests").
  • Assert on behavior the user can observe, not on mock calls or private internals.
  • Bug fix: first a test that reproduces the bug (RED), then the fix. The test stays as a regression guard.
  • Regression proof: a test is trustworthy once you've seen it fail with the fix reverted and pass with it restored.

Choosing the level

Before the first test of a task, read references/test-standard.md. It is the single source of the test rules: expected values, which tests are worth writing, names, doubles, determinism, retries, flakes, which level verifies which criterion, coverage and changing tests. Follow the project's existing test stack and layout.

With BDD scenarios: outside-in. For a user-visible criterion, write its scenario first (references/bdd.md) and run it: it must fail on the step that needs the missing behavior (the outer RED). Then drive the code with the cycle above, one unit test at a time (the inner loops); each unit test checks its unit's own contract and stays (test-standard, "Criteria and levels"). The criterion is done when its scenario passes. Don't write scenarios for criteria you aren't working on yet.

Red flags: stop and start over

ThoughtReality
"Too simple to test"Simple code breaks. The test takes a minute.
"I'll add tests after"Tests written after pass immediately, which proves nothing.
"I tested it manually"Manual testing can't be re-run and covers no edge cases. It replaces a test only where automation is impossible, and only with the user's agreement.
"Deleting this work is wasteful"That's sunk cost. Keeping untrusted code is the real waste.
"Hard to test"Then it's hard to use. Simplify the interface or inject the dependency.
"Just this once"That's how every skipped test starts.

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.