Test-Driven Development
Target: $ARGUMENTS
Writes focused, behavior-driven tests following the TDD Red-Green-Refactor cycle. Language-agnostic — works with any test framework (pytest, vitest, jest, cargo test, etc.).
Quick Reference
- TDD cycle + anti-patterns:
references/tdd-best-practices.md
- What to test/skip + mocking strategy:
references/testing-strategy.md
TDD Cycle
- RED — Write a failing test that describes the expected behavior
- GREEN — Write minimal code to make the test pass
- REFACTOR — Improve code quality while tests stay green
- Repeat
Never skip RED. Every feature starts with a failing test.
Test Structure: Arrange-Act-Assert
Every test has three phases:
ARRANGE — Set up test data and dependencies
ACT — Execute the behavior under test
ASSERT — Verify the outcome
What to Test (KISS/DRY/YAGNI)
High-Value (test these):
- Business logic — algorithms, calculations, decision rules
- Integration points — API handling, external service interactions
- Edge cases — empty inputs, error propagation, boundary conditions
- Contracts — response formats, data transformations
Avoid (skip these):
- Library behavior — framework internals, third-party validation
- Trivial assertions — existence checks, type checks, default values
- Implementation details — internal state, private methods
- Styling/layout — CSS, class names
See references/testing-strategy.md → "Patterns to Remove" for full list.
Decision Checklist
Before writing a test:
- Does this test behavior (write it) or implementation (skip it)?
- Would this catch a real bug (write it) or is it trivial (skip it)?
- Is this testing our code (write it) or a library (skip it)?
Mocking Strategy
- Mock external dependencies (APIs, network, filesystem)
- Mock non-deterministic values (time, random, UUIDs)
- Use real services when in-memory alternatives exist
- Constrain mocks to real interfaces (typed mocks, spec=)
- Never mock internal functions in the same module
Quality Gates
1---2name: testing-tdd3description: Writes tests following TDD Red-Green-Refactor cycle. Language-agnostic methodology with Arrange-Act-Assert structure. Use when implementing features test-first.4---56# Test-Driven Development78**Target**: $ARGUMENTS910Writes **focused, behavior-driven tests** following the TDD Red-Green-Refactor cycle. Language-agnostic — works with any test framework (pytest, vitest, jest, cargo test, etc.).1112## Quick Reference1314- TDD cycle + anti-patterns: `references/tdd-best-practices.md`15- What to test/skip + mocking strategy: `references/testing-strategy.md`1617## TDD Cycle18191. **RED** — Write a failing test that describes the expected behavior202. **GREEN** — Write minimal code to make the test pass213. **REFACTOR** — Improve code quality while tests stay green224. Repeat2324**Never skip RED.** Every feature starts with a failing test.2526## Test Structure: Arrange-Act-Assert2728Every test has three phases:2930```31ARRANGE — Set up test data and dependencies32ACT — Execute the behavior under test33ASSERT — Verify the outcome34```3536## What to Test (KISS/DRY/YAGNI)3738**High-Value** (test these):39- Business logic — algorithms, calculations, decision rules40- Integration points — API handling, external service interactions41- Edge cases — empty inputs, error propagation, boundary conditions42- Contracts — response formats, data transformations4344**Avoid** (skip these):45- Library behavior — framework internals, third-party validation46- Trivial assertions — existence checks, type checks, default values47- Implementation details — internal state, private methods48- Styling/layout — CSS, class names4950See `references/testing-strategy.md` → "Patterns to Remove" for full list.5152## Decision Checklist5354Before writing a test:55561. Does this test **behavior** (write it) or **implementation** (skip it)?572. Would this catch a **real bug** (write it) or is it **trivial** (skip it)?583. Is this testing **our code** (write it) or **a library** (skip it)?5960## Mocking Strategy6162- Mock external dependencies (APIs, network, filesystem)63- Mock non-deterministic values (time, random, UUIDs)64- Use real services when in-memory alternatives exist65- Constrain mocks to real interfaces (typed mocks, spec=)66- Never mock internal functions in the same module6768## Quality Gates6970- [ ] Every feature starts with a failing test (RED)71- [ ] Tests use Arrange-Act-Assert structure72- [ ] No tests for library internals or implementation details73- [ ] Mocks use spec/type constraints (no untyped mocks)74- [ ] Test names describe behavior, not methods75- [ ] All tests pass before committing