StoicBuilder

HandbookVIII the PalaestraTest-driven development

VIIIthe Palaestra, Test it

Test-driven development

1 min readUpdated 28 November

In plain words

Test-driven development is a loop: write a test for the next small behaviour, watch it fail, write the least code that makes it pass, then tidy up while the tests stay green.

Where you see it

Before Harbor adds annual plans, you write a test saying a year of Pro costs ten months of the monthly price. It fails, because annual plans don't exist yet. You hand the agent the red test and ask for code that turns it green without touching the test.

lib/billing/price.test.tsterminal
test("annual Pro costs ten months of monthly Pro", () => { expect(price({ plan: "pro", interval: "year" })).toBe(30000);}); // Red: run it before the code exists, and watch it fail// Green: write the least code that makes it pass// Refactor: tidy up while it stays green
The test comes first, so it states the rule before any code can bend it.

What goes wrong

  1. Skipping the red step

    A test that has never failed might not test anything: it may call the wrong function or never reach its assertion. Watch it fail once, for the reason you expect, before writing the code.

  2. Letting the agent write the test and the code together

    The agent produces code and a test that agree with each other, including on the bug. Write or approve the test first, commit it, then ask for code that passes it without editing the test.

  3. Steps that are too big

    A test for the whole billing system takes a day to turn green, and the loop stops giving you feedback. Pick the next smallest behaviour and add one case at a time.

What to tell your agent

Copy this into Lovable, Bolt, Cursor or any agent
We're working test first. Write one failing Vitest test for the next behaviour, run it and show me it failing, then stop. Once I approve it, write the least code that makes it pass without changing the test, and run the whole suite.

Quick check

Sign in to earn +10 XP for it

You write a test for annual pricing before the feature exists, and it passes on the first run. What does that tell you?

Got a prompt that touches Test-driven development?

Paste it. You get a better prompt first, then the cards that explain it.

Check your own prompt

Free, no sign-up.