Skill · Coding
tdd-vertical-slices
Implements a feature test-first, one small user-visible behavior at a time: write a failing test, confirm it fails for the right reason, write the least code to pass, refactor while green, checkpoint, and log each cycle. Use when asked to do TDD, write tests first, red-green-refactor, or build a feature in small tested steps.
The skill itself. Agents read the name and description first and load the rest only when a task matches.
tdd-vertical-slices/SKILL.md
---
name: tdd-vertical-slices
description: "Implements a feature test-first, one small user-visible behavior at a time: write a failing test, confirm it fails for the right reason, write the least code to pass, refactor while green, checkpoint, and log each cycle. Use when asked to do TDD, write tests first, red-green-refactor, or build a feature in small tested steps."
---
# TDD in vertical slices
## Steps
1. Find the test command and framework the repo already uses (package scripts, Makefile, CI config). Use them; don't add a new framework.
2. List the behaviors the feature needs as short user-visible statements ("rejects an expired coupon"). Order them smallest and most central first. Show the list before starting.
3. Pick the next behavior. Write one test for it at the highest seam that is still fast: a module's public API, an HTTP handler, a component as the user sees it.
4. Run the test. Confirm it fails, and that it fails for the right reason: an assertion about the behavior, not a typo, import error or missing fixture. If it passes, the test is wrong or the behavior already exists; fix the test or move on.
5. Write the least production code that makes it pass. Hard-coding is fine if a later test will force the general case.
6. Run the test and the related test files. Everything is green.
7. Refactor while green: names, duplication, structure. Run the tests after each change.
8. Checkpoint: commit with a message naming the behavior if the user wants a commit per cycle; otherwise note the cycle as a checkpoint and leave committing to them.
9. Add a row to the cycle log and go back to step 3.
## Rules
- No production code without a failing test that needs it.
- One behavior per cycle. If a test needs two things to change, split it.
- Never change a test and the code in the same step to get to green.
- Test through public interfaces. Don't mock your own internals; mock only at system edges (network, clock, randomness, paid APIs).
- Don't use snapshot tests for logic; keep them for stable output formats.
- Assert outcomes, not implementation details such as which function was called or in what order.
- If two attempts don't get the test green, undo the production changes since the last green checkpoint and split the behavior into a smaller one.
- Don't skip the run where you watch it fail, even when you're sure.
## Example output
| # | Behavior | Test | Failed because | Change | Result |
|---|---|---|---|---|---|
| 1 | Applies a 10% coupon | `cart.test.ts: applies percent coupon` | total was 100, expected 90 | added `applyCoupon` | green, committed |
| 2 | Rejects an expired coupon | `cart.test.ts: rejects expired` | no error thrown | date check in `applyCoupon` | green, extracted date helper, committed |