Modern QA2026Template 3: Test-Driven Prompting — tiles
Log inJoin
6 / 87 · 02 AI-Augmented Test Design · Prompt Templates for Test Generation← prev⊞ allnext →☰ Read as one page

2.4Template 3: Test-Driven Prompting

This template flips the script: you describe the desired behavior, and the LLM generates both the tests and the implementation. Useful for TDD workflows and interview demonstrations.

I need a function called `{function_name}` with this behavior:

- Accepts: {input signature}
- Returns: {output signature}
- Rules:
  {list all business rules, one per line}

Generate:
1. FIRST: A complete test file covering every rule, including boundary values
   ({list specific boundary values}) and every {category, e.g., destination category}.
2. THEN: The implementation that makes all tests pass.

Complete Example

I need a function called `calculate_shipping_cost` with this behavior:

- Accepts: { weight_kg: number, destination_country: string, is_express: boolean }
- Returns: { cost_usd: number, estimated_days: number }
- Rules:
  - Base rate: $5 + $2 per kg
  - Express multiplier: 1.5x cost, halves estimated days (round up)
  - Domestic (US): 5 days standard
  - Canada/Mexico: 7 days standard
  - Europe: 10 days standard
  - All other: 14 days standard
  - Max weight: 30kg. Over 30kg raises ValueError.
  - Negative weight raises ValueError.
  - Zero weight is valid (just the base rate).

Generate:
1. FIRST: A complete test file covering every rule, including boundary values
   (0kg, 30kg, 30.01kg, -1kg) and every destination category.
2. THEN: The implementation that makes all tests pass.

Why This Pattern Is Powerful

This pattern is powerful in interviews because it demonstrates that you think specification-first, not code-first. It also produces a natural test-implementation pair that is self-documenting. The tests serve as the executable specification for the function.

In practice, this pattern works best for:

  • Pure functions with clear input/output contracts
  • Utility functions shared across the codebase
  • Business logic with well-defined rules
  • Data transformation and validation functions