agentleFS
milad-raeisimilad-raeisi/senior-skills/skills/test-driven-development/SKILL.md

test-driven-development

Skill4 starsChanged 15 days agoMITView on GitHub

Test-first development that produces tests worth keeping. Use when implementing a feature, fixing a bug, or changing behavior that can be tested, when the user mentions TDD, red-green-refactor, regression tests, or test coverage, and whenever a bug fix needs a test proving it stays fixed. Works in vertical slices (one failing test, minimal code, repeat), tests behavior through public interfaces, and avoids mock-heavy, tautological, and implementation-coupled tests.

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

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

  • 0

    Common

    Most of the 182 edited versions we read keep these.

  • 7

    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:

    Red: Write one small test for the next piece of behavior.

    line 16
  2. Distinctive:

    Green: Write the minimum code that makes it pass.

    line 17
  3. Distinctive:

    One reason to fail: When it fails, the name and message tell you what broke.

    line 29
  4. Distinctive:

    Fast and deterministic: No real network, wall-clock time, or shared global state.

    line 30
  5. Distinctive:

    Prefer the lowest test level that can observe the behavior: unit for pure logic, integration for boundaries (database queries, HTTP …

    line 49
  6. Distinctive:

    Visual layout: Use screenshots or visual review, and test the logic behind the view.

    line 54
  7. Distinctive:

    Legacy code without seams: Start with characterization tests that pin current behavior at the highest practical level, then refactor toward …

    line 55

“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

A test written first proves two things a test written later can't: that the test can fail, and that the code you wrote is what made it pass. TDD is not about coverage numbers. It is about building in small steps where each step is proven before the next one starts.

The loop

  1. Red. Write one small test for the next piece of behavior. Run it and watch it fail for the right reason: an assertion about the missing behavior, not a typo, import error, or missing fixture.
  2. Green. Write the minimum code that makes it pass. Hard-coding is allowed if the next test will force generality.
  3. Refactor. With tests green, clean up names, duplication, and structure. Run the tests after each change.
  4. Repeat with the next behavior.

Work in vertical slices: one test, one implementation, repeat. Writing all the tests first commits you to a design before you've learned anything from implementing it, and produces tests of imagined behavior.

For a bug fix, the first test reproduces the bug. It must fail before the fix and pass after. If you can't make it fail, you haven't reproduced the bug yet (see systematic-debugging).

What makes a test worth keeping

  • Tests behavior through the public interface. It reads like a specification ("rejects checkout when cart is empty") and survives refactoring, because it doesn't know how the code is structured inside.
  • Independent expected values. Expected results come from the spec, a worked example, or a known-good literal, never from recomputing them the way the code does.
  • One reason to fail. When it fails, the name and message tell you what broke.
  • Fast and deterministic. No real network, wall-clock time, or shared global state. Inject a clock, seed randomness, and use in-memory or containerized dependencies.
  • Mocks only at real boundaries. Mock what you don't own and can't run cheaply (payment APIs, email, time). Don't mock your own internal collaborators; use the real ones.

Anti-patterns

Anti-patternTellFix
Implementation-coupledBreaks on refactor while behavior is unchangedAssert on outputs and observable effects at the interface
Tautologicalexpect(add(a, b)).toBe(a + b)Use independent known values
Mock theaterThe test mostly verifies that mocks were calledUse real collaborators; mock only external boundaries
Snapshot dumpingHuge snapshots nobody reads, updated blindlyAssert the few properties that matter
Testing the frameworkAsserting that the ORM saves or the router routesTest your logic, not the library's
Flaky by designSleeps, real time, order-dependent testsInject time, await conditions, isolate state
Green without redTest never seen failingBreak the code (or revert the fix) and confirm the test fails

Choosing what to test

You can't test everything, so put tests where bugs are likely and expensive: business rules, state transitions, parsing and validation, money and time calculations, permission checks, and anything that has broken before. Thin glue code and pure configuration rarely earn dedicated tests.

Prefer the lowest test level that can observe the behavior: unit for pure logic, integration for boundaries (database queries, HTTP handlers), end-to-end for a few critical user journeys.

When test-first doesn't fit

  • Exploratory spikes. Prototype freely to learn, then throw the spike away and rebuild test-first, or at least add tests before calling it done.
  • Visual layout. Use screenshots or visual review, and test the logic behind the view.
  • Legacy code without seams. Start with characterization tests that pin current behavior at the highest practical level, then refactor toward testable seams.

In every case, behavior changes ship with tests, and the tests have been seen to fail.

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.