# Test-Driven Development (tdd)

> Builds features and fixes bugs test-first in a red-to-green loop, testing behavior only at public seams agreed with the user.

- Category: [Testing & Debugging](https://www.myskills.tools/en/categories/testing-debugging/)
- Source: Community · Matt Pocock
- Repository: https://github.com/mattpocock/skills/tree/main/skills/engineering/tdd (commit 3f59913)
- SKILL.md: https://github.com/mattpocock/skills/blob/main/skills/engineering/tdd/SKILL.md
- Install command: `npx skills add mattpocock/skills --skill tdd`
- License: MIT
- Compatible with: Claude Code, Codex, Copilot, Gemini CLI
- Permissions: read-repo ✓, write-files ✓, shell ✓, network ✗
- Status: Scan passed
- A rule scan cannot catch every risk. Read this skill's SKILL.md and check its permissions before installing.

## Core rule

Red before green: write the failing test first, then only enough code to pass it.

## Execution Phases

1. **Learn the domain language** — Read GLOSSARY.md if it exists so test names match the project's language, and respect ADRs in the area.
2. **Agree on the seams** — Write down the seams under test, each with a one-line note on what it catches and misses, and confirm them with the user.
3. **Write one failing test** — Test behavior through the public interface at one seam, with expected values from an independent source of truth.
4. **Minimal implementation** — Write only enough code to pass the test, without anticipating future tests or adding speculative features.
5. **Repeat in vertical slices** — Repeat one test and one implementation per cycle; refactoring is not part of the loop and belongs to the code review stage.

## Permissions (summarised from SKILL.md)

| Capability | Needed | Details |
|---|---|---|
| File writes | Required | Writes tests and the implementation code that makes them pass. |
| Command execution | Tests only | Runs tests to see them fail, then pass. |
| Network outbound | Not required | The workflow has no network steps. |

## SKILL.md frontmatter (YAML)

```yaml
---
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.
---
```

Home: https://www.myskills.tools/en/ · URL: https://www.myskills.tools/en/skills/tdd/
