tdd
Test-Driven Development workflow. Use for ALL code changes - features, bug fixes, refactoring. TDD is non-negotiable.
Best use case
tdd is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Test-Driven Development workflow. Use for ALL code changes - features, bug fixes, refactoring. TDD is non-negotiable.
Teams using tdd should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/tdd/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How tdd Compares
| Feature / Agent | tdd | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Test-Driven Development workflow. Use for ALL code changes - features, bug fixes, refactoring. TDD is non-negotiable.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
Related Guides
AI Agents for Coding
Browse AI agent skills for coding, debugging, testing, refactoring, code review, and developer workflows across Claude, Cursor, and Codex.
Cursor vs Codex for AI Workflows
Compare Cursor and Codex for AI coding workflows, repository assistance, debugging, refactoring, and reusable developer skills.
SKILL.md Source
# Test-Driven Development
TDD is the fundamental practice. Every line of production code must be written in response to a failing test.
This skill focuses on the TDD workflow/process.
---
## RED-GREEN-REFACTOR Cycle
### RED: Write Failing Test First
- NO production code until you have a failing test
- Test describes desired behavior, not implementation
- Test should fail for the right reason
### GREEN: Minimum Code to Pass
- Write ONLY enough code to make the test pass
- Resist adding functionality not demanded by a test
- Commit immediately after green
### REFACTOR: Assess Improvements
- Assess AFTER every green (but only refactor if it adds value)
- Commit before refactoring
- All tests must pass after refactoring
---
## TDD Evidence in Commit History
### Default Expectation
Commit history should show clear RED → GREEN → REFACTOR progression.
**Ideal progression:**
```
commit abc123: [MAINTENANCE] Add failing test for user authentication
commit def456: [NEW FEATURE] Implement user authentication to pass test
commit ghi789: [MAINTENANCE] Extract validation logic for clarity
```
### Rare Exceptions
TDD evidence may not be linearly visible in commits in these cases:
**1. Multi-Session Work**
- Feature spans multiple development sessions
- Work done with TDD in each session
- Commits organized for PR clarity rather than strict TDD phases
- **Evidence**: Tests exist, all passing, implementation matches test requirements
**2. Context Continuation**
- Resuming from previous work
- Original RED phase done in previous session/commit
- Current work continues from that point
- **Evidence**: Reference to RED commit in PR description
**3. Refactoring Commits**
- Large refactors after GREEN
- Multiple small refactors combined into single commit
- All tests remained green throughout
- **Evidence**: Commit message notes "refactor only, no behavior change"
### Documenting Exceptions in PRs
When exception applies, document in PR description:
```markdown
## TDD Evidence
RED phase: commit c925187 (added failing tests for shopping cart)
GREEN phase: commits 5e0055b, 9a246d0 (implementation + bug fixes)
REFACTOR: commit 11dbd1a (test isolation improvements)
Test Evidence:
✅ 4/4 tests passing (7.7s with 4 workers)
```
**Important**: Exception is for EVIDENCE presentation, not TDD practice. TDD process must still be followed - these are cases where commit history doesn't perfectly reflect the process that was actually followed.
---
## Coverage Verification - CRITICAL
### NEVER Trust Coverage Claims Without Verification
**Always run coverage yourself before approving PRs.**
### Verification Process
**Before approving any PR claiming "100% coverage":**
1. Check out the branch
```bash
git checkout feature-branch
```
2. Run coverage verification:
```bash
uv run pytest --cov --cov-report=term-missing
```
3. Verify ALL metrics hit 100%:
- Lines: 100% ✅
- Statements: 100% ✅
- Branches: 100% ✅
- Functions: 100% ✅
4. Check that tests are behavior-driven (not testing implementation details)
**Watch for anti-patterns that create fake coverage (coverage theater).**
### Reading Coverage Output
Look for the "All files" line in coverage summary:
```
Name Stmts Miss Cover Missing
-------------------------------------------------
src/models.py 42 0 100%
src/services.py 38 0 100%
src/utils.py 15 0 100%
-------------------------------------------------
TOTAL 95 0 100%
```
✅ This is 100% coverage.
### Red Flags
Watch for these signs of incomplete coverage:
❌ **PR claims "100% coverage" but you haven't verified**
- Never trust claims without running coverage yourself
❌ **Coverage summary shows <100%**
```
TOTAL 95 8 92%
```
- This is NOT 100% coverage
❌ **"Missing" column shows line numbers**
```
src/services.py 38 5 87% 45-48, 52
```
- Lines 45-48 and 52 are not covered
❌ **Coverage gaps without exception documentation**
- If coverage <100%, document the reason and get approval
### When Coverage Drops, Ask
**"What business behavior am I not testing?"** — not "What line am I missing?"
---
## Development Workflow
### Adding a New Feature
1. **Write failing test** — describe expected behavior
2. **Run test** — confirm it fails (`uv run pytest`)
3. **Implement minimum** — just enough to pass
4. **Run test** — confirm it passes
5. **Refactor if valuable** — improve code structure
6. **Commit** — following project commit convention
### Workflow Example
```python
# 1. Write failing test
def test_reject_empty_user_names():
result = create_user(id="user-123", name="")
assert result.success is False # ❌ Test fails (no implementation)
# 2. Implement minimum code
def create_user(id: str, name: str) -> CreateUserResult:
if not name:
return CreateUserResult(success=False, error="Name required")
... # ✅ Test passes
# 3. Refactor if needed (extract validation, improve naming)
# 4. Commit
# git add . && git commit -m "[NEW FEATURE] Reject empty user names"
```
---
## Pull Request Requirements
Before submitting PR:
- [ ] All tests must pass
- [ ] All linting and type checks must pass
- [ ] **Coverage verification REQUIRED** - claims must be verified before review/approval
- [ ] PRs focused on single feature or fix
- [ ] Include behavior description (not implementation details)
---
## Refactoring Priority
After green, classify any issues:
| Priority | Action | Examples |
|----------|--------|----------|
| Critical | Fix now | Mutations, knowledge duplication, >3 levels nesting |
| High | This session | Magic numbers, unclear names, >30 line functions |
| Nice | Later | Minor naming, single-use helpers |
| Skip | Don't change | Already clean code |
For detailed refactoring methodology, load the `refactoring` skill.
---
## Anti-Patterns to Avoid
- ❌ Writing production code without failing test
- ❌ Testing implementation details (spies on internal methods)
- ❌ 1:1 mapping between test files and implementation files
- ❌ Using mutable module-level state or fixtures for shared test data
- ❌ Trusting coverage claims without verification
- ❌ Mocking the function being tested
- ❌ Redefining schemas in test files
- ❌ Factories returning partial/incomplete objects
- ❌ Speculative code ("just in case" logic without tests)
---
## Summary Checklist
Before marking work complete:
- [ ] Every production code line has a failing test that demanded it
- [ ] Commit history shows TDD evidence (or documented exception)
- [ ] All tests pass
- [ ] Coverage verified at 100% (or exception documented)
- [ ] Test factories used (no shared mutable state)
- [ ] Tests verify behavior (not implementation details)
- [ ] Refactoring assessed and applied if valuable
- [ ] Commit messages follow project convention (see `commit-convention.md`)Related Skills
worklog
Update worklog files by moving tasks between todo/doing/done states. Use when recording task progress, starting new work, or marking tasks complete. Requires explicit arguments: worklog [done|doing|todo] [description].
template-proposal-review
Review proposal files in localdocs/localdocs/proposals/ and decide whether to apply them to the upstream python-project-template repository. Use when evaluating proposals generated by template-upstream, deciding which ones to accept or reject, and applying accepted ones to the template repo. Triggers on: "proposal 검토", "제안 검토", "template에 반영할지", "proposals 리뷰", "upstream 반영 결정".
template-downstream
Update .claude/, .mcp.json, and .pre-commit-config.yaml from the upstream python-project-template repository into the current project. Only files that exist upstream are updated — project-only files are never deleted. Use when pulling latest tooling, rules, hooks, or skills from the canonical template into this project. Triggers on: "템플릿 최신화", "template sync", "upstream 반영", "template 업데이트".
template-broadcast
Apply template-downstream to all registered downstream projects in bulk, one project at a time. Use when you want to push the latest .claude/, .mcp.json, or .pre-commit-config.yaml to every project at once. Triggers on: "일괄 배포", "전체 프로젝트에 내려보내기", "모든 프로젝트 업데이트", "broadcast template", "bulk sync".
sparks-create
Apply the 13 thinking tools from "Sparks of Genius" (생각의 탄생) to reframe any problem through creative, cross-disciplinary lenses. Use when conventional analysis falls short, when you need a fresh creative angle, or when the problem spans multiple domains.
skill-creator
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.
rethink-unblock
Break out of a stuck approach by reframing a technical problem through structured thinking frameworks. Use when blocked, going in circles, or when a fresh perspective is needed on architecture, design, or debugging.
refactoring
Refactoring assessment and patterns. Use after tests pass (GREEN phase) to assess improvement opportunities.
python-mcp-expert
Expert assistant for developing Model Context Protocol (MCP) servers in Python. Use when creating, debugging, or optimizing MCP servers with FastMCP, tools, resources, and prompts.
python-conventions
Python coding conventions and guidelines including PEP 8, type hints, docstrings, and testing standards. Automatically applied when working with Python files.
prd
Generate high-quality Product Requirements Documents (PRDs) for software systems and AI-powered features. Includes executive summaries, user stories, technical specifications, and risk analysis.
planning
Planning work in small, known-good increments. Use when starting significant work or breaking down complex tasks.