# Test First

> Use when implementing any feature or bugfix in a codebase with a test suite. Enforces red-green-refactor so the test proves the change instead of decorating it.

- Skill: `dkenge123-oss/test-first` (Agent Skill)
- Install (CLI): `npx skillmds@latest add dkenge123-oss/test-first`
- Raw SKILL.md: https://api.skillmd.com/api/skills/dkenge123-oss/test-first/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: dkenge123-oss (https://skillmd.com/u/dkenge123-oss)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/dkenge123-oss/test-first

---


# Test First

A test written after the code passes because the code exists. A test written before the code passes because the behavior exists. Only the second one proves anything.

## Protocol

1. **Write the failing test first.** Express the desired behavior as a test before touching implementation code. For a bugfix, the test reproduces the bug.
2. **Run it and watch it fail.** This step is not optional. A test that passes before the fix is a broken test. Confirm the failure message matches the reason you expect.
3. **Write the minimum code to pass.** Resist implementing beyond what the test demands. Unrequested generality is where bugs hide.
4. **Run the full relevant suite**, not just the new test. Your change is not done if it broke a neighbor.
5. **Refactor with green as your safety net.** Now improve names, remove duplication, simplify. Re-run tests after each refactor step.
6. **Review the test for honesty.** Would it still fail if the implementation regressed? Delete assertions that cannot fail.

## Choosing what to test

- Test the behavior at the boundary the caller sees, not private internals.
- One test per behavior, named for the behavior: `retries_three_times_then_raises`.
- Cover the unhappy path. Most production incidents live in error handling.

## Never

- Never mark work done with a failing or skipped test.
- Never weaken an existing assertion to make your change pass without understanding why it fired.
- Never mock so much that the test only exercises the mocks.

## Done means

New behavior has a test that failed before the change and passes after. The full suite is green. The test would catch a regression.

