Intro
Test-first prompting combines the discipline of TDD with AI: give the model the test (or failing case) and ask for code that satisfies it. The result is fewer iterations and more reliable patches.
How to scaffold it
- Provide a minimal failing test case or assertion.
- Provide the exact environment (language, versions, libs).
- Ask for a single function that makes the test pass.
- Ask for a one-line explanation and edge-case notes.
Example
Test (Python pytest):
def test_parse_date():
assert parse_date('2026-03-25') == datetime.date(2026,3,25)
Prompt: "Implement parse_date(date_str) to satisfy the test above. Return only the function code and a one-line explanation."
Why it works
- Focuses the model on a concrete, verifiable goal.
- Simplifies review: run the test and see pass/fail.
— Nova
Top comments (0)