Development Process
Test-Driven Development
Enforces the red-green-refactor cycle so every feature starts with a failing test before any implementation code is written.
Last reviewed Mar 2, 2026
Install
Create this file in your project:
.claude/skills/test-driven-development/SKILL.md---
name: test-driven-development
description: Use this skill whenever writing new functionality, fixing bugs, or refactoring existing code. Enforces the red-green-refactor cycle.
---
# Test-Driven Development
## When to Use
- Adding new features or behaviors
- Fixing bugs (write a test that reproduces the bug first)
- Refactoring existing code (ensure tests exist before changing)
## Process
1. **Red** -- Write a single failing test that describes the expected behavior. Run it. Confirm it fails for the right reason.
2. **Green** -- Write the minimum implementation code to make the failing test pass. Do not add extra logic.
3. **Refactor** -- Clean up the implementation and the test. Remove duplication, improve naming, simplify logic. Run tests again to confirm they still pass.
4. Repeat for the next behavior.
## Rules
- Never write implementation code without a failing test first.
- One behavior per test. If a test name contains "and", split it.
- Keep tests fast. Mock external services, databases, and network calls.
- Test behavior, not implementation details. Tests should survive refactors.
- Name tests descriptively: `should [expected behavior] when [condition]`.
- If a test is hard to write, the design needs to change -- listen to the tests.
- Run the full test suite after each green-refactor cycle before moving on.What this skill does
Test-Driven Development (TDD) is a disciplined approach where every line of production code is justified by a failing test. This skill instructs the AI agent to follow the classic red-green-refactor loop: first write a test that fails, then write just enough code to pass it, then clean up.
The key benefit is that TDD produces code with high test coverage by default. Because every feature starts as a test, you never end up with untested code paths. The tight feedback loop also catches design problems early -- if something is hard to test, it usually means the design needs improvement.
This skill is especially valuable when working with AI coding assistants because it provides a natural checkpoint system. The agent must prove each step works before moving to the next, preventing the common failure mode of generating large blocks of untested code.
Example workflow
You ask the agent to add a calculateDiscount function that applies tiered pricing. The agent will:
- Write a test:
should return 0% discount for orders under $50-- run it, see it fail (function doesn't exist). - Create the function returning 0 -- test passes.
- Write next test:
should return 10% discount for orders between $50 and $100-- run it, see it fail. - Add the conditional logic -- test passes.
- Continue for each tier, then refactor to eliminate duplication.
Tips
- Start with the simplest possible test case to get the function signature right
- When fixing a bug, always write the reproducing test before touching any implementation code
- If you find yourself wanting to skip TDD for "simple" code, that's exactly when hidden bugs creep in
- Use TDD as a design tool -- the tests tell you what API feels natural to use
Best with tools
Related MCP servers
- No linked MCP servers yet.
Related skills
Brainstorming
Collaborative idea-to-design exploration that asks clarifying questions, proposes approaches with tradeoffs, and iterates toward a design.
Executing Plans
Execute implementation plans task-by-task with verification checkpoints, sequential ordering, and frequent commits.
Systematic Debugging
Enforces a structured debugging workflow: reproduce, hypothesize, verify, fix root cause, and audit similar code paths.