Turn a Coding Agent into a Test-First TDD Partner
Direct a coding agent to write failing tests first, then implement just enough code to pass them.
Get higher-quality, regression-resistant changes by enforcing a red-green-refactor loop with the agent.
At a glance
Access
Free prompt
Open to copy — no account or payment needed.
Prompt objective
Get higher-quality, regression-resistant changes by enforcing a red-green-refactor loop with the agent.
Real use case
A team's coding agent writes implementation and tests together, so the tests just rubber-stamp whatever it built. They want genuine test-first discipline.
Customize these fields first
Replace the placeholders with your own context before you run the prompt. That usually improves the first output more than adding more instructions later.
Prompt
You are a test-driven development partner working as a coding agent. Follow strict red-green-refactor. Feature to build: [DESCRIBE BEHAVIOR] Language/test framework: [E.G. TYPESCRIPT + VITEST] Existing patterns to follow: [POINT TO EXAMPLES] Loop, one behavior at a time: 1. RED: write a single failing test that specifies the next smallest behavior. Show the test and explain what it asserts. Run it and confirm it fails for the right reason. 2. GREEN: write the minimum implementation to make that test pass — no extra features. Run the test and confirm it passes. 3. REFACTOR: improve naming/structure without changing behavior; keep all tests green. 4. Restate which behaviors remain, then repeat. Rules: never write implementation ahead of a test; keep each step tiny; do not delete or weaken a test to make it pass; report the test count and pass/fail after each loop. Start with the first RED test now.
Open directly in an AI — the text is pre-filled:
How to use this prompt
- 1Replace the key placeholders first: DESCRIBE BEHAVIOR, E.G. TYPESCRIPT + VITEST, POINT TO EXAMPLES.
- 2Replace any bracketed placeholders like [this] with your own context.
- 3Add extra background information when you want more tailored results.
- 4Combine multiple prompts in one conversation when you need a richer output.
- 5Save your best-performing prompts so they are easy to reuse later.
Next best step
Open the guide first, then branch only if you still need more.
A guide for technical builders choosing between prompts, coding workflows, and agent-based implementation.
If this prompt is close but not quite right, generate variants next. If the job is recurring, move into the course library after the guide.
Related prompts
View allBrief a Coding Agent (Claude Code / Codex) on a Real Task
Write a precise task brief for an autonomous coding agent so it ships the right change without wandering across the codebase.
Best for
Get a self-contained brief — context, constraints, definition of done — that lets a coding agent work safely in an existing repo.
Plan-Then-Execute Mode for a Coding Agent
Force a coding agent to produce and confirm an implementation plan before it edits a single file.
Best for
Prevent expensive wrong turns by separating planning from execution and getting a checkpoint before changes land.
Debug with an Agent Using a Hypothesis-Driven Loop
Guide a coding agent to debug systematically — form a hypothesis, add instrumentation, test it, narrow down — instead of random edits.
Best for
Find the real root cause faster by forcing structured, evidence-based debugging rather than shotgun fixes.
Explore other prompt categories
Move sideways into adjacent libraries when the current category is not the full answer.
Every prompt here is free. The course teaches the thinking behind them.
Copy as many prompts as you like. When you want to move from single prompts to a repeatable AI workflow, Learn AI in 30 Days walks through it, one day at a time.
Buy the course once ($15/$20 by length), or go all-access for $10/mo with a verifiable certificate.