Test-driven development

Drives a change with the red, green, refactor loop: write a failing test that states the behavior, add the minimal code to pass, then refactor with tests green. Use when building a feature or fixing a bug test-first, or when asked for TDD.

TestingPack: Testing91 linestest-driven-development

Install

Run one command — it saves SKILL.md into your agent's skills folder. Restart the agent and the skill is picked up automatically.

Claude Code — macOS, Linux
mkdir -p ~/.claude/skills/test-driven-development && curl -fsSL https://anymodel.org/en/skills/testing/test-driven-development/SKILL.md -o ~/.claude/skills/test-driven-development/SKILL.md
Codex, Cursor — macOS, Linux
mkdir -p ~/.agents/skills/test-driven-development && curl -fsSL https://anymodel.org/en/skills/testing/test-driven-development/SKILL.md -o ~/.agents/skills/test-driven-development/SKILL.md
Claude Code — Windows PowerShell
New-Item -ItemType Directory -Force "$HOME\.claude\skills\test-driven-development" | Out-Null; Invoke-WebRequest https://anymodel.org/en/skills/testing/test-driven-development/SKILL.md -UseBasicParsing -OutFile "$HOME\.claude\skills\test-driven-development\SKILL.md"
Codex, Cursor — Windows PowerShell
New-Item -ItemType Directory -Force "$HOME\.agents\skills\test-driven-development" | Out-Null; Invoke-WebRequest https://anymodel.org/en/skills/testing/test-driven-development/SKILL.md -UseBasicParsing -OutFile "$HOME\.agents\skills\test-driven-development\SKILL.md"

Any other agent: save the file into its skills folder, or give it the link to the file: https://anymodel.org/en/skills/testing/test-driven-development/SKILL.md

SKILL.md

Raw

Test-Driven Development

TDD is a loop of small steps. The test comes first because it forces you to state the behavior before you write the code that provides it.

Before the loop

  1. Find the project's test runner and command (package.json scripts, pytest.ini, go test, Makefile). Run the existing suite once so you know the baseline: which tests pass, which already fail.
  2. Look at one or two existing tests and copy their style: file location, naming, helpers, fixtures, assertion library.
  3. Write down the behavior you need as a short list of examples in plain words. Each example becomes a test, smallest first.
- empty cart totals 0
- one item totals price * quantity
- coupon reduces the total by its percentage
- expired coupon is rejected with an error

The loop

Red: write one failing test

  • Test one behavior, named after the behavior ("rejects expired coupon"), not the method.
  • Use the public interface the real callers will use. Write the call as you wish it existed, even if the function does not exist yet.
  • Run it. It must fail, and for the right reason: the assertion fails or the missing function is reported. If it fails for an unrelated reason (import error, typo, broken setup) fix that first. If it passes immediately, the test is useless or the behavior already exists; stop and understand which.

Green: make it pass with the least code

  • Write the simplest code that makes this one test pass. Returning a constant is allowed if it is the first example; the next test will force generality.
  • Do not add behavior no test demands. Do not handle cases you have not written a test for.
  • Run the new test and then the whole relevant suite. All green before moving on.

Refactor: clean up with tests green

  • Remove duplication, rename, extract functions, simplify conditions, in both the code and the tests.
  • Run the tests after each small change. If a test goes red, undo the last step instead of debugging a large edit.
  • Do not change behavior during refactoring. If you want new behavior, go back to red.

Then pick the next example from your list and repeat. Keep each cycle to a few minutes of work.

Bug fixes

  1. Write a test that reproduces the bug and watch it fail.
  2. Fix the code until it passes.
  3. Run the full suite. The test stays as a regression guard.

Choosing the order of tests

  • Start with the simplest case (empty, zero, one), then add cases that force new code paths.
  • Then boundaries (limits, off-by-one), then errors and invalid input.
  • Add the happy path integration test last, once the pieces work.

Test quality rules

  • One reason to fail per test. Prefer one logical assertion.
  • Assert outcomes (return value, stored data, emitted event), not internal calls. Mock only at boundaries such as network, clock, filesystem or third-party services.
  • Tests must be independent and deterministic: no order dependence, no real time, no random without a seed.
  • Failure messages should tell what was expected and what happened.

When TDD is a bad fit

Say so and use another approach when:

  • Exploring an unknown API or a UI layout: spike first, throw the spike away or add tests after you understand it.
  • Pure glue or configuration with no logic of its own.
  • Visual styling and pixel details; use a screenshot or manual check instead.
  • Code that is expensive to run in tests (real hardware, paid services). Test the logic around it and put a thin adapter at the edge.
  • A throwaway script the user will not keep.

In those cases still add tests for any real logic afterward.

Report format

  • Behaviors implemented, in order, with the test names.
  • For each cycle: the failing message seen in red (short), then green.
  • Final suite result (counts) and the command used.
  • What you did not cover and why.

Pitfalls

  • Writing all the tests first and all the code after. Work one test at a time.
  • Skipping the red step. A test you never saw fail may not test anything.
  • Editing a test to make it pass when the code is wrong. Change a test only if the requirement changed, and tell the user.
  • Testing implementation details so every refactor breaks the tests.
  • Large steps. If green takes more than ten minutes, the test was too big; split it.

Source: AnyModel skills catalog · License: CC BY 4.0

Connect through AnyModel API

This skill runs on whatever model your agent uses. Point Claude Code, Codex or Cursor at AnyModel to run it on Claude, GPT, Gemini and more with one key — pay per token, no subscription.

More from the pack Testing