tddlisted
Install: claude install-skill tomcounsell/ai
# Skill: /tdd
## Purpose
Scaffold a test-driven development cycle: write a failing test first, implement the minimal code to pass it, then refactor — with an explicit gate that the test is red before any implementation is written.
## When to Use
- Implementing a new function, class, or module from scratch
- Fixing a bug where a regression test should prevent recurrence
- The user says "tdd this", "write tests first", or "red-green-refactor"
- Any feature work where correctness is more important than speed of first draft
## Steps
1. **Understand the behavior to implement.** Read any referenced plan, issue, or existing tests. Clarify the acceptance criterion in one sentence: "Given X, when Y, then Z."
2. **Write the failing test (RED).** Create the test file before writing any implementation:
Example — adding a `parse_duration` function:
```python
# tests/unit/test_parse_duration.py
import pytest
from tools.time_utils import parse_duration
def test_parse_duration_minutes():
assert parse_duration("5m") == 300
def test_parse_duration_hours():
assert parse_duration("2h") == 7200
def test_parse_duration_invalid_raises():
with pytest.raises(ValueError, match="invalid duration"):
parse_duration("banana")
```
3. **Run the test and confirm it FAILS.** This is a hard gate — do not write implementation until you see a red failure:
```bash
pytest tests/unit/test_parse_duration.py -v
```
Expected: `FAILED` or