home / skills / zpankz / mcp-skillset / test-driven-development
This skill enforces test-driven development by writing failing tests first, then minimal code to satisfy them, ensuring correct behavior.
npx playbooks add skill zpankz/mcp-skillset --skill test-driven-developmentReview the files below or copy the command above to add this skill to your agents.
---
name: test-driven-development
description: Use when implementing any feature or bugfix, before writing implementation code - write the test first, watch it fail, write minimal code to pass; ensures tests actually verify behavior by requiring failure first
---
# Test-Driven Development (TDD)
## Overview
Write the test first. Watch it fail. Write minimal code to pass.
**Core principle:** If you didn't watch the test fail, you don't know if it tests the right thing.
**Violating the letter of the rules is violating the spirit of the rules.**
## When to Use
**Always:**
- New features
- Bug fixes
- Refactoring
- Behavior changes
**Exceptions (ask your human partner):**
- Throwaway prototypes
- Generated code
- Configuration files
Thinking "skip TDD just this once"? Stop. That's rationalization.
## The Iron Law
```
NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST
```
Write code before the test? Delete it. Start over.
**No exceptions:**
- Don't keep it as "reference"
- Don't "adapt" it while writing tests
- Don't look at it
- Delete means delete
Implement fresh from tests. Period.
## Progressive Loading
**L2 Content** (loaded when methodology details needed):
- See: [references/methodology.md](./references/methodology.md)
- Red-Green-Refactor Cycle
- Good Tests Principles
- Why Order Matters
- Common Rationalizations
- Verification Checklist
**L3 Content** (loaded when advanced patterns needed):
- See: [references/anti-patterns.md](./references/anti-patterns.md)
- Testing Mock Behavior
- Test-Only Methods
- Mocking Without Understanding
- Incomplete Mocks
- Integration Tests as Afterthought
- Quick Reference Guide
This skill codifies a strict test-driven development (TDD) workflow for JavaScript work: write the test first, confirm it fails, implement the minimal code to make it pass, then refactor. It enforces the core principle that a test must fail before it can prove anything, preventing false confidence from prewritten implementation. Use this skill to keep behavior verification accurate and development focused on requirements.
Before adding or changing production code, author a failing automated test that expresses the desired behavior or bug fix. Run the test suite, observe the new test fail, then implement the smallest change needed to pass. Once green, clean up the code and tests while keeping behavior coverage intact. Repeat this Red-Green-Refactor cycle for every feature, bug fix, and refactor.
What if the test never fails?
If a test doesn't fail initially, it likely isn't exercising the intended behavior. Revisit the test to ensure it targets production code paths and that the test environment matches runtime conditions.
Is TDD required for quick prototypes?
Not always. For throwaway prototypes or experiments, TDD can slow iteration. Use judgment and switch to TDD when the prototype becomes production-bound.
How strict must I be about deleting prewritten code?
Strict. If production code exists before a failing test, it can mask issues. Delete or revert that code and start the test-first flow to preserve test validity.