Writing tests (TDD-style loop)
Grow tests around a small pricing calculator using a tight feedback loop with your agent.
Goal
Practice a TDD-leaning loop: small unit tests first, run them on every turn, refactor only when green. The exercise is about verification and tight feedback, not 100% coverage in one session.
Getting started
The repository ships a small pricing calculator with plenty of branches and almost no tests. Pick the language you prefer and follow that path.
dotnet testYou should see one passing test. Source is in
Pricing/PriceCalculator.cs. Tests go in
Pricing.Tests/PriceCalculatorTests.cs.
npm install
npm testSame shape. Source in src/pricing.ts, tests in
tests/pricing.test.ts.
What the calculator does
The class combines bracket-tier discounts (5% from 10, 10% from 50, 15% from 100), a few promo codes including one that is expired, and country based VAT (GB 20%, DE 19%, US 0%). Negative prices throw. Zero quantity returns zero. Plenty to test.
Loop to practice
Prompt patterns that work
- "Add tests under
Pricing.Tests(ortests/). No production behavior change. Cover [behavior] only." - "After each edit, run
[exact command]and paste exit code 0 or the failure. Do not claim green without a run." - "List untested branches in
PriceCalculator.Totaland propose one test per branch. Implement only the first test first."
Constraints
- Do not hand the model CI secrets or production credentials.
- If the repo uses snapshots or golden files, commit the approved outputs deliberately. Do not let the agent silence flakiness by deleting tests.
Done when
You have a reproducible test command, several unit tests in one focused area, and a short note: what the agent misunderstood about the module boundaries and how you corrected it.