Vibe Coding for Production
Exercises

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 test

You should see one passing test. Source is in Pricing/PriceCalculator.cs. Tests go in Pricing.Tests/PriceCalculatorTests.cs.

npm install
npm test

Same 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

Run the suite to confirm the one starter test passes.
Choose a small testable behavior: one tier, one promo code, one VAT country, one validation rule.
Write a failing test in plain language in chat, then have the agent implement the test and make it pass with the smallest change. Or write the test yourself and let the agent implement the fix.
Run the suite after every substantive edit. If the agent claims to be done without a green run, reject the batch and require command output in the next message.
Repeat for three to five tests, then refactor once with the suite still green.
Stop and summarize: which tests pin behavior and which would you delete as redundant?

Prompt patterns that work

  • "Add tests under Pricing.Tests (or tests/). 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.Total and 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.

See also

On this page