| name | tdd |
| description | Test-Driven Development workflow. Tests BEFORE code. Red-green-refactor cycle. Triggers: tdd, test-first, test-driven, red-green, coverage. |
| allowed-tools | Read, Bash, Write, Edit, Grep, Glob |
1. agentdb read-start — check for existing test patterns in codebase.
2. Identify test framework in use (Jest, Vitest, pytest).
3. Check _meta/research/ for prior TDD work.
skills/tdd/reference/tdd-research.md — mocking patterns, framework examples, coverage config, organization strategies
1. Write user journey: "As a [role], I want [action], so that [benefit]"
2. Generate test cases from journey (happy path, edge cases, errors)
3. Write tests first.
(gate: `npm test` / `pytest` exits non-zero — tests must FAIL red before proceeding)
4. Implement MINIMAL code to pass — no anticipatory features.
(gate: `npm test` / `pytest` exits zero — all tests GREEN)
5. Refactor while keeping tests green.
(gate: tests still pass after every change; file ends same length or shorter)
6. Verify coverage >= 80% branches/functions/lines/statements.
(gate: coverage report shows >= 80% on all axes)
<core_principles>
- TESTS DEFINE BEHAVIOR: Write tests from requirements, not implementation. Test what SHOULD happen.
- MINIMAL CODE: Write only enough code to make the test pass. No anticipatory features.
- REFACTOR WHILE GREEN: Clean up only when tests pass. Never refactor red.
- 80% COVERAGE MINIMUM: Unit + integration + E2E. All edge cases covered.
- ONE ASSERT PER TEST: Test names are specifications. Split if "and" appears.
</core_principles>
<anti_patterns>
Writing code then tests validates bugs. Test first or not at all.
Test behavior, not structure. Refactoring should not break tests.
One behavior per test. If you need "and", split the test.
Use semantic selectors ([data-testid], role), not CSS classes.
Each test must be independent. No shared state between tests.
</anti_patterns>
<on_complete>
agentdb write-end '{"skill":"tdd","tests_written":,"coverage":"<X%>","cycle":"red->green->refactor","failures_caught":[""]}'
Record test count, coverage achieved, and what edge cases the tests catch.
</on_complete>