tdd
Test-Driven Development methodology and discipline. Use when writing code test-first, practicing Red-Green-Refactor, building walking skeletons, applying…
by vinnie357★ 30 GitHub stars
Install tdd in Claude Code & Claude Desktop
Sign up to install this skill
Create a free account to reveal the install command and save the skill to your library.
- Reveal the one-line install command
- Save skills to your synced library
- Get notified when skills update
About this skill
Test-Driven Development
A discipline for growing software guided by tests, one small step at a time.
The TDD Cycle
Five Steps
- Write a test list — brainstorm the tests you think you'll need
- Write one failing test — pick the next test from the list
- Make it pass — write the simplest code that makes the test green
- Refactor — remove duplication and improve design, keeping tests green
- Repeat — pick the next test, update the list as you learn
Red-Green-Refactor
The micro-cycle is a three-state machine:
┌──────────────────────────────────────┐
│ │
▼ │
[RED] ──── write minimal code ────► [GREEN] ──── refactor ────► [GREEN]
▲ │
│ │
└──────────── write next failing test ◄──────────────────────────┘
RED: Write a test that fails. Confirm it fails for the right reason — the missing behavior, not a syntax error or wrong import.
GREEN: Make the test pass with the simplest change possible. "Sinful" code is fine — hardcoded values, copy-paste, whatever gets green fastest.
REFACTOR: Clean up while all tests stay green. Remove duplication between test and production code. Improve names. Extract methods. This is where design emerges.
Rules:
- Never write production code without a failing test
- Never write more test code than needed to fail
- Never write more production code than needed to pass
The Three Laws
Uncle Bob's formalization of Beck's constraints:
- You shall not write production code unless you have a failing test
- You shall not write more of a test than is sufficient to fail (including compile failures)
- You shall not write more production code than is sufficient to pass the currently failing test
These laws enforce the micro-cycle. They keep steps small and feedback immediate.
Test List
A test list is a brainstorm of all the tests you think you'll need, written before you start coding. It is your roadmap.
How to Create One
- Think about the behavior you need to implement
- List the specific cases: happy path, edge cases, error cases
- Order them from simplest to most complex
- Start with a degenerate case if possible
Example: Stack
Test List:
- [ ] new stack is empty
- [ ] push one item, stack is not empty
- [ ] push one item then pop, returns that item
- [ ] push two items then pop, returns second item
- [ ] pop empty stack raises error
- [ ] push and pop multiple items (LIFO order)
- [ ] peek returns top without removing
When to Update
The test list is alive. As you work:
- Cross off completed tests
- Add new tests you discover along the way
- Remove tests that turn out to be redundant
- Reorder if a different sequence makes more sense
A test list can seed beads tasks — create one task per test with skill:tdd labels for tracking.
Strategies for Getting to Green
Three strategies for making a failing test pass, in order of safety:
Fake It
Return a hardcoded value that makes the test pass. Then write the next test to force generalization.
# Test: add(1, 2) returns 3
# Fake It:
def add(a, b):
return 3
# Next test forces real implementation:
# Test: add(3, 4) returns 7
When to use: When you're unsure how to implement the real thing. When the step to real code feels too big. When you want maximum safety.
Obvious Implementation
Type the real implementation directly, because it's clear what the code should be.
# Test: add(1, 2) returns 3
# Obvious Implementation:
def add(a, b):
return a + b
When to use: When the implementation is trivially obvious. When you're confident. If you get an unexpected failure, fall back to Fake It.
Triangulation
Use two or more test cases to force removal of hardcoded values and drive toward the general solution.
# Test 1: add(1, 2) returns 3
def add(a, b):
return 3 # fake it
# Test 2: add(3, 4) returns 7
def add(a, b):
return a + b # now forced to generalize
When to use: When you're uncertain about the abstraction. When two examples make the pattern clearer than one. When you need confidence before generalizing.
Test Sequencing
"As tests get more specific, code gets more generic." — Robert C. Martin
Start with degenerate cases and progress toward forcing generalization:
- Degenerate/boundary cases — null, empty, zero, one element
- Simple happy path — the most basic successful case
- Variations — different inputs that exercise the same path
- Edge cases — boundaries, maximums, special values
- Error cases — invalid input, missing data, failure conditions
Each new test should require a small, incremental change to the production code. If a test requires a large change, you skipped a step — find a simpler te
Allowed tools
Tools this skill is permitted to call.
No restriction — this skill can use any tool.
Bundled files
- references/beck-tdd.md
- references/ci-discipline.md
- references/goos-outside-in.md
- references/os-subprocess-boundary.md
FAQ
What does the tdd skill do?
Test-Driven Development methodology and discipline. Use when writing code test-first, practicing Red-Green-Refactor, building walking skeletons, applying outside-in development, or sequencing tests for incremental design.
How do I install the tdd skill?
Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.
Does the tdd skill run scripts?
No, this skill is instructions only (SKILL.md) with no executable scripts.
Related skills
doc-coauthoring
AnthropicGuide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
academy-guide
AnthropicStop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
internal-comms
AnthropicA set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
skill-development
AnthropicThis skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…