Test-driven prompting

Write the tests first and ask the AI to make them pass.

Draft: open for discussionAlso known as: TDD with AI, tests-first

Definition

You express the contract as executable tests, then ask the model to implement until they pass, without touching the tests. Tests turn a vague request into an objective target and give both you and the model a fast feedback loop. It works especially well with agents that can run the test suite on their own.

Example prompt

The test file is written by you. The prompt only sets the rules.

Test-driven prompting
// carousel.test.ts (written by you)it('shows the 5 most recent images', ...)it('advances every 5 seconds', ...)it('pauses while hovered', ...)it('flashes twice on transition', ...)it('skips an image that fails to load', ...)Implement <HomeCarousel /> so every test in carousel.test.ts passes.Do not modify the test file. Run the tests after each changeand stop when they are all green.

What it reveals

  • Thinking in contracts and observable behavior
  • Commitment to quality and verification
  • Ability to design testable code

Use it when

  • Logic with clear inputs and outputs
  • Bug fixes: write the failing test first
  • Agent workflows where the model can run the tests itself

Watch out for

  • The model cheating: special-casing tests or quietly editing them
  • Tests that only cover the happy path
  • Testing implementation details instead of behavior

In an interview

Look for

  • Do the tests describe behavior or implementation?
  • Does the candidate check that the model did not weaken the tests?

Ask

  • Which test is missing from this suite?
  • How would you notice if the model had special-cased a test?

Origin

Derived from test-driven development (TDD), which Kent Beck rediscovered and popularized through Extreme Programming and described in "Test-Driven Development: By Example" (2002). Beck himself later applied TDD to coding agents in "Augmented Coding: Beyond the Vibes" (2025), and Simon Willison documents "red/green TDD" as an agentic engineering pattern. Nobody is credited with the name "test-driven prompting".

Kent Beck2002

Sources