Test-driven prompting supplies executable behavioral tests as specifications for AI-generated code. It keeps requirements explicit, makes known edge cases part of generation, and provides immediate verification instead of relying on code that merely looks plausible. section 8.3.3
Use the workflow as an engineering loop:
- Write tests that define correct behavior, emphasizing edge cases and difficult combinations. section 8.3.3
- Include the tests in the prompt and request an implementation that passes them; naming Red-Green-Refactor can encourage structured output. section 8.3.3
- Run the tests, then regenerate or debug failures and add tests when new cases appear. section 8.3.3
Parser contract
A test such as assert parse_markup("**bold *italic* text**") == "<strong>bold <em>italic</em> text</strong>" specifies nested formatting without prescribing regexes, parser combinators, or state machines. A separate test can require that "#### Not a header" remain unchanged. section 8.3.3 section 8.3.7
This is specification-driven generation rather than traditional one-test-at-a-time TDD. Tests express intent—the what, not the how—but passing tests only establishes that enumerated cases satisfy the contract. Unimagined cases remain uncovered, so manual exploration and additional evaluation still matter. section 8.3.3 section 8.3.7
