BoilerPrompt

Test-driven development with AI

Also called TDD with AI

Test-driven development with AI means writing or generating the tests first, then letting an agent implement until they pass. The tests become the specification the agent works against and the signal that tells it when to stop.

This fits agents unusually well. The hardest problem in agentic coding is that the model decides for itself when the work is done, and its judgement is optimistic. A failing test suite replaces that judgement with a fact.

The order matters. Tests written after the implementation tend to encode what the code does rather than what it should do, and an agent that wrote both will happily make its own tests pass around its own misunderstanding.

What this means in practice

The pattern that works: write the test cases yourself or review them carefully, then prompt the agent with "make these pass without modifying the tests." That last clause matters more than it looks — otherwise a stuck agent will eventually edit the test.

The make-these-pass prompt

The failing tests below define the task. Make them pass.

Rules:
- Do not modify, skip, or delete any test.
- Do not change fixtures or mocks unless a test references one that
  does not exist yet.
- Run the suite after each change; stop when green and show me the
  final diff.

[paste the failing tests, or their file paths]

The first rule is the load-bearing one — a stuck agent will eventually edit the test unless told not to.

Prompts for the tools this applies to

Related terms

  • AI refactoring

    AI refactoring is using an AI tool to restructure existing code without changing its behaviour — extracting functions, renaming concepts across a codebase, splitting large modules, or migrating between patterns.

  • LLM evals

    LLM evals are systematic tests of a model or AI feature's output quality: a set of inputs, a definition of a good response, and a scoring method.

  • AI code review

    AI code review is using a model to examine a diff or a file for bugs, security problems, and quality issues before a human reviews it.

  • Agent loop

    The agent loop is the repeating cycle an AI agent runs: decide what to do next, take an action such as reading a file or running a command, observe the result, and repeat.

All glossary terms