Coding
AI Prompt for Test-Driven Development
Practice TDD with this AI prompt: turn acceptance criteria into failing tests first, then get implementation guidance for the red-green-refactor cycle.
The prompt
Role: You are a TDD coach guiding strict red-green-refactor discipline. Context: Language: [LANGUAGE], framework: [FRAMEWORK]. Feature: [FEATURE_DESCRIPTION]. Acceptance criteria: [ACCEPTANCE_CRITERIA as concrete examples] Task: 1) Write the failing tests FIRST — one per acceptance criterion, in priority order. Each test must fail for the right reason (missing functionality, not syntax errors). 2) For each test, state the MINIMAL implementation step that would make it pass (TDD baby steps). 3) After the tests, suggest the natural implementation structure that emerges. 4) List the refactor opportunities to look for once all tests pass. Format: Tests first (all failing), then the baby-step implementation guide, then the suggested structure, then refactor targets. Ask the AI to define 'done' for each baby step: the exact assertion that must pass before you move on. Vague steps invite gold-plating; crisp assertions keep the red-green cycle tight. Constraints: Tests before implementation — no production code in your answer except the baby-step guidance. Each test covers exactly one acceptance criterion. Keep the first test embarrassingly simple.
Variables to fill in
Replace each [variable] in the prompt with your own details:
[LANGUAGE] [FRAMEWORK] [FEATURE_DESCRIPTION] [ACCEPTANCE_CRITERIA]
Example input
FEATURE=user can apply coupon codes at checkout, LANGUAGE=TypeScript, FRAMEWORK=Vitest, ACCEPTANCE=valid code → discount applied; expired → error; unknown → error; case-insensitive
How to use this prompt
Write acceptance criteria as concrete examples BEFORE generating — TDD tests encode the spec. List the behaviors in priority order; implement in that order.
Tips for the best results
- Run the tests to confirm they fail for the right reason before writing any implementation.
- Follow the baby steps literally — the discipline is the point of TDD.
- Ask the AI to review your implementation after green for the refactor phase.
Frequently asked questions
I write the implementation, right?
It writes the failing tests from your acceptance criteria; you write the implementation until they pass — classic red-green-refactor.
TDD feels slow. Is it worth it?
For complex logic, yes — the tests become your safety net for every future change. For trivial CRUD, the prompt's baby steps will tell you the tests add little.