# /test-driven-development: Strict red-green-refactor test-driven development

Source: https://trendhub.net/skills/obra-superpowers/test-driven-development
Skill folder: https://github.com/obra/superpowers/tree/main/skills/test-driven-development
Pack: Superpowers (https://trendhub.net/skills/obra-superpowers)
Works with: Claude Code, Claude Code (Superpowers marketplace), Codex CLI, Cursor, Gemini CLI, GitHub Copilot CLI, Devin CLI, Qwen Code, Pi, Antigravity

This skill makes the agent write a failing test before any production code, confirm it fails for the right reason, add the smallest code that passes, then clean up while staying green. Code written before its test is deleted and redone, and the full project test suite must pass before the work counts as finished.

## When to use it

- Adding a new feature or changing existing behavior
- Fixing a bug, so a test proves the fix
- Refactoring code that should keep behaving the same

## How it works

1. **Red**: Write one small test with a clear name that describes a single behavior.
2. **Verify red**: Run it and confirm it fails because the feature is missing, not because of a typo or error.
3. **Green**: Write the minimum code needed to pass, without extra options or unrelated changes.
4. **Verify green**: Run the test and the whole project suite, and report any failures by name.
5. **Refactor**: Remove duplication and improve names while keeping every test passing.

## What it steers the agent away from

- Tests written after the code that pass immediately and prove nothing
- Tests that check mock behavior instead of real code
- Over-engineered code built for needs nobody stated

## What it can touch

Edits test and source files and runs the project's test commands (for example npm test, pytest or cargo test) in your shell; it may delete code that was written before its test.

## Pairs well with

- `/systematic-debugging`
- `/verification-before-completion`
- `/subagent-driven-development`
- `/writing-plans`

## Questions

### Are there exceptions to test-first?

The skill lists throwaway prototypes, generated code and configuration files as possible exceptions, but only after asking you.

### Is passing the new test enough?

No. It expects the project's whole test suite to run green, and any failing test, even one the agent did not cause, must be reported.
