9 / 14 · Book 2 · The Anatomy of a Test-Generation Prompt← prev⊞ allnext →Get the book →
1.9The Prompt Iteration Loop
Prompt engineering is not one-shot. The first prompt rarely produces perfect output. Use this iteration loop:
1. DRAFT the prompt with all five elements
2. GENERATE a small batch (5-10 tests)
3. EVALUATE: Are assertions correct? Are APIs real? Is the style right?
4. REFINE the prompt based on what was wrong
5. REGENERATE with the improved prompt
6. REPEAT until output quality is consistently high
7. SAVE the refined prompt as a template for future use
This loop typically converges in 2-3 iterations. The investment in prompt refinement pays off every time you reuse the template for a similar feature.
Iteration example:
Iteration 1 output problem: AI used jest instead of vitest
Prompt fix: Added explicit import statement to constraints
Iteration 2 output problem: AI generated only happy-path tests Prompt fix: Added explicit negative-to-positive ratio guidance
Iteration 3 output: Quality meets standards. Save as template.