Build with AI and trust what you make. Free guide, no signup

Test first

Write the tests, or have AI write them, then let AI iterate until they pass. Good when you can pin the behaviour down up front and want a safety net as you go.

yesnoagainYour testsAI implementsTests pass?Share the failuresDone
This is the Test first box from the diagram at the top, opened up. You write the tests first, the AI implements against them, and every failure goes back until they pass. Then you are done.

Doing this with Claude Code: Test first

Test first works when you can pin the behaviour down: set the target up front, make it a rule, drive the coverage, keep each test concrete and let the suite become the net.

The target up front. Write the test before the code so the behaviour is set, the then in a Given, When, Then becomes what the test checks.

A rule, not a suggestion. Once it exists Claude has to meet it, it runs, it fails, you hand back the failures until it passes.

Drive the coverage. The happy path is not enough, ask for the edge cases too, the null, the empty, the huge input.

Keep each test concrete. It meets exactly what you wrote and not what you meant, so a vague test passes while still being wrong.

It becomes the net. The suite checks the change now and catches it later when something new breaks it.

Common questions

  1. Why write the test before the code exists?
    So the target is set up front rather than after the fact. It builds straight on your examples, where the "then" in a Given, When, Then becomes the thing the test actually checks.
  2. What changes once the test exists?
    The test becomes a rule Claude has to meet rather than a suggestion. It runs, it fails, you hand the failures back, and Claude keeps trying until it passes.
  3. What is the catch with testing first?
    A test meets exactly what you wrote down and not what you meant. So keep each one concrete and focused, or it passes while the code is still wrong.
  4. Can I leave the coverage to Claude?
    Drive it yourself, because the happy path is not enough. Ask for the edge cases and the slow paths too, the null, the empty and the huge input, or it tests the obvious case and stops.
  5. What is the suite worth after the change is done?
    It checks the change now and becomes the net that catches it later, when some new piece of work breaks something old that nobody thought to look at.

Back to For developers. The craft around it is Working with AI.