Skip to content
TDD

TDD Skill

Matt Pocock's test-driven development skill: one red-to-green slice at a time, tests only at seams agreed with you first, and a named list of test anti-patterns to avoid.

GitHub Docs

Install

Install with the skills CLI

One command for Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf and dozens of other agents. Needs Node.js; the skill is fetched straight from mattpocock/skills.

$ npx skills add mattpocock/skills --skill tdd

Run it in a terminal. The CLI finds the agents installed on your machine, asks which ones to add the skill to, and whether to install it into the folder you ran it from or for all your projects.

Other ways to install

Copy the whole skill folder — SKILL.md and any scripts or references beside it — into ~/.claude/skills/tdd/, where Claude Code picks it up in every project. Only git is needed.

tmp=$(mktemp -d) && \
  git clone --depth 1 --branch main https://github.com/mattpocock/skills.git "$tmp" && \
  mkdir -p ~/.claude/skills && \
  cp -R "$tmp"/skills/engineering/tdd ~/.claude/skills/tdd

No scripts or references next to it? Saving the SKILL.md alone as ~/.claude/skills/tdd/SKILL.md works too.

Using another agent? Its personal skills folder
Codex
~/.agents/skills/
Cursor
~/.cursor/skills/
GitHub Copilot
~/.copilot/skills/
Gemini CLI
~/.gemini/skills/
Windsurf
~/.codeium/windsurf/skills/
OpenCode
~/.config/opencode/skills/

About

  • Agrees the seams to test with you before writing any test
  • Strict vertical slices: one test, one minimal implementation
  • Names implementation-coupled, tautological and horizontal-slice anti-patterns
  • Uses the project glossary and ADRs for test vocabulary

TDD is the test-driven development skill from Matt Pocock's skills collection, one of the most installed on skills.sh. It loads when you ask an agent to build a feature or fix a bug test-first, mention red-green-refactor, or want integration tests, and it acts as a reference the agent consults on every cycle rather than a one-off checklist.

Its central idea is the seam: the public boundary where behaviour can be observed without reaching inside. Before writing any test, the agent proposes the seams it intends to test, with a note on what each catches and misses, and waits for you to confirm them, so testing effort lands on critical paths instead of every edge case. Tests then verify behaviour through those interfaces and should survive refactoring.

The skill names three anti-patterns: implementation-coupled tests that mock internals or check side channels, tautological tests whose expected value is computed the same way as the code, and horizontal slicing, writing all tests before any implementation. Instead it enforces vertical slices: one test, the minimal code to pass it, repeat. Refactoring is kept out of the loop and left to review. It reads the project's GLOSSARY.md and ADRs so test names match the domain, and it calls the companion codebase-design skill for interface vocabulary. MIT-licensed.

SKILL.md

The instructions your agent loads, as published by Matt Pocock.

SKILL.md
name
tdd
description
Test-driven development. Use when the user wants to build features or fix bugs test-first, mentions "red-green-refactor", or wants integration tests.

Test-Driven Development

TDD is the red → green loop. This skill is the reference that makes that loop produce tests worth keeping: what a good test is, where tests go, the anti-patterns, and the rules of the loop. Every section applies on every cycle: consult them before and during the loop, not after.

When exploring the codebase, read GLOSSARY.md (if it exists) so test names and interface vocabulary match the project's domain language, and respect ADRs in the area you're touching.

What a good test is

Tests verify behavior through public interfaces, not implementation details. Code can change entirely; tests shouldn't. A good test reads like a specification: "user can checkout with valid cart" tells you exactly what capability exists, and it survives refactors because it doesn't care about internal structure.

See [tests.md](tests.md) for examples and [mocking.md](mocking.md) for mocking guidelines.

Seams: where tests go

A seam is the public boundary you test at: the interface where you observe behavior without reaching inside. Tests live at seams, never against internals.

Test only at pre-agreed seams. Before writing any test, write down the seams under test and confirm them with the user. No test is written at an unconfirmed seam. You can't test everything, so agreeing the seams up front is how testing effort lands on the critical paths and complex logic instead of every edge case.

Ask: "What's the public interface, and which seams should we test?" Give each proposed seam a one-line note on what it catches and what it misses.

When the shape of that interface is itself in question (how deep the module is, where the seam belongs, what the interface should expose), call the Skill tool with "codebase-design" for the vocabulary. It is the shared source of the module, interface, depth, seam, adapter, leverage and locality terms, and it is a reference to consult, not a session to run.

Anti-patterns
  • Implementation-coupled: mocks internal collaborators, tests private methods, or verifies through a side channel (querying the database instead of using the interface). The tell: the test breaks when you refactor but behavior hasn't changed.
  • Tautological: the assertion recomputes the expected value the way the code does (expect(add(a, b)).toBe(a + b), a snapshot derived by hand the same way, a constant asserted equal to itself), so it passes by construction and can never disagree with the code. Expected values must come from an independent source of truth: a known-good literal, a worked example, the spec.
  • Horizontal slicing: writing all tests first, then all implementation. Bulk tests verify _imagined_ behavior: you test the _shape_ of things rather than user-facing behavior, the tests go insensitive to real changes, and you commit to test structure before understanding the implementation. Work in vertical slices instead: one test → one implementation → repeat, each test a tracer bullet that responds to what the last cycle taught you.
Rules of the loop
  • Red before green. Write the failing test first, then only enough code to pass it. Don't anticipate future tests or add speculative features.
  • One slice at a time. One seam, one test, one minimal implementation per cycle.
  • Refactoring is not part of the loop. It belongs to the review stage (see the code-review skill), not the red → green implementation cycle.
Install

Reduces accumulated complexity without changing behaviour, using Chesterton's Fence to avoid deleting the thing that was load-bearing.

Matt Pocock's /improve-codebase-architecture command: finds shallow modules worth deepening, renders them as a visual HTML report with before/after diagrams, then grills you through the one you pick.

Skill: Diagnosing Bugs

by Matt Pocock

New

Matt Pocock's discipline for hard bugs and performance regressions: build a tight, red-capable feedback loop first, then reproduce, minimise, hypothesise, instrument, fix with a regression test and clean up.

Browse all skills →