---
name: tdd-workflow
description: Build features and fix bugs test-first: write one failing test, write the least code to pass it, then refactor with the tests green. Use when implementing a feature or bug fix where tests can run, or when the user asks for TDD.
license: Proprietary — Lendskill original
---

# Test First

## The loop
1. **Red** — write one small test for the next behaviour. Run it and watch it fail for the right reason (not a typo or import error).
2. **Green** — write the simplest code that makes it pass. Hard-coding is fine at this stage; the next test will force the real logic.
3. **Refactor** — remove duplication and improve names while every test stays green.
4. Repeat with the next behaviour.

## Choosing the next test
Order: the simplest happy path → variations → edge cases (empty, zero, one, many, max) → error cases. One behaviour per test; name it as a sentence: `returns_empty_list_when_no_orders`.

## Rules
- Never write production code without a failing test that asks for it.
- If a test passes immediately, it is testing nothing new: check it or delete it.
- Keep tests fast and independent: no shared state, no order dependence, no real network.
- Mock only at boundaries you do not own (HTTP, clock, payment provider), never your own logic.
- For a bug: the first test reproduces the bug and must fail before the fix.

## Output format
For each cycle: the test, the run result (fail), the code change, the run result (pass), and any refactor. End with the full test list and the command to run them.
