agentleFS
DevelopersGlobalDevelopersGlobal/ai-agent-skills/skills/test-driven-development/SKILL.md

test-driven-development

Skill216 starsChanged 6 months agoMITView on GitHub

Red-green-refactor cycle with meaningful coverage. Tests are written before implementation. Coverage is a side effect of good tests, not the goal.

We split this skill into the rules it gives an agent

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

  • 0

    Common

    Most of the 179 edited versions we read keep these.

  • 13

    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 a test for the behavior you want — before writing implementation.

    line 25
  2. Distinctive:

    Run the test. Confirm it fails for the right reason (not a syntax error — a missing implementation).

    line 29
  3. Distinctive:

    Verify: Test runs and fails with a clear "not implemented" or "undefined" error.

    line 31
  4. Distinctive:

    Write the minimum implementation to make the test pass.

    line 35
  5. Distinctive:

    Do not write more than the test requires — resist the urge to add logic for future cases.

    line 36
  6. Distinctive:

    Run the test. Confirm it passes.

    line 37
  7. Distinctive:

    Verify: All tests pass. No new tests added yet.

    line 39
  8. Distinctive:

    Run tests after every refactoring step — do not batch refactors.

    line 44
  9. Distinctive:

    If tests break during refactor: revert immediately, refactor more carefully.

    line 45
  10. Distinctive:

    Test pyramid: many unit tests, fewer integration tests, minimal end-to-end tests.

    line 52
  11. Distinctive:

    Run coverage report. Flag any critical paths with 0% coverage.

    line 56
  12. Distinctive:

    Do NOT chase a coverage number — write tests for behaviors that matter.

    line 57
  13. Distinctive:

    Verify: All happy paths and key edge cases have tests.

    line 59

“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

Overview

TDD is the discipline of writing a failing test before writing implementation code. It forces you to think about the interface before the internals, produces tests that actually test behavior (not just coverage), and gives you a safety net for every refactor.

AI agents skip tests constantly. This skill makes tests non-optional.

When to Use

  • Starting any new feature or function
  • Fixing any bug (write a test that reproduces the bug first)
  • Refactoring existing code (ensure test coverage before you start)

Process

Step 1: Write a Failing Test (Red)

  1. Write a test for the behavior you want — before writing implementation.
  2. The test should describe what the code does, not how:
    • ✅ test("returns 404 when user not found")
    • ❌ test("calls findById with the user id")
  3. Run the test. Confirm it fails for the right reason (not a syntax error — a missing implementation).

Verify: Test runs and fails with a clear "not implemented" or "undefined" error.

Step 2: Write Minimum Code (Green)

  1. Write the minimum implementation to make the test pass.
  2. Do not write more than the test requires — resist the urge to add logic for future cases.
  3. Run the test. Confirm it passes.

Verify: All tests pass. No new tests added yet.

Step 3: Refactor (Refactor)

  1. Now clean up the implementation — no new behavior, only improved structure.
  2. Run tests after every refactoring step — do not batch refactors.
  3. If tests break during refactor: revert immediately, refactor more carefully.

Verify: Tests still pass after refactor. Code is cleaner.

Step 4: Repeat for Each Behavior

  1. Repeat steps 1–3 for each distinct behavior of the feature.
  2. Test pyramid: many unit tests, fewer integration tests, minimal end-to-end tests.

Step 5: Coverage Sanity Check

  1. Run coverage report. Flag any critical paths with 0% coverage.
  2. Do NOT chase a coverage number — write tests for behaviors that matter.

Verify: All happy paths and key edge cases have tests. Coverage report reviewed.

Common Rationalizations (and Rebuttals)

ExcuseRebuttal
"I'll add tests after"After never comes. And after-the-fact tests test your implementation, not the behavior.
"This code is too simple to test"Simple code breaks in unexpected ways when requirements change.
"Integration tests are enough"Unit tests catch bugs faster, run faster, and localize failures better.
"We don't have time for TDD"You have time for the bug investigation that comes without TDD?

Red Flags

  • Tests were written after the implementation
  • Tests test internal implementation details (private methods, DB queries) rather than behavior
  • "Happy path only" test coverage
  • Tests pass even when you break the implementation (mocked away the real behavior)
  • Coverage target hit by testing trivial getters/setters

Verification

  • Tests written before implementation (or alongside for bug fixes)
  • Each test describes a specific behavior
  • Red-green-refactor cycle followed
  • All tests pass
  • Key edge cases covered (empty input, null, boundary values)
  • Coverage report reviewed for critical path gaps

References

  • debugging-methodology skill
  • references/testing-patterns.md

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.

Reviews can't be read right now.

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.