The prompt
Score 10 of 10, Excellent
Use it when You want a coding agent to write tests from a function's spec or rules, not from its code, and report the failures as suspected bugs.
- {{function_path}}
- {{intended_behavior}}
- {{test_command}}
- {{pattern_test_file}}
- {{known_cases}}
Full prompt and why it works
Prompt
Goal: Write tests for {{function_path}} that check it against what it is supposed to do, as described below, so that we find out whether it is correct, not only what it currently does. What the function is supposed to do (spec, ticket, docstring or business rules): """ {{intended_behavior}} """ Context: - Test framework and command: {{test_command}} - Existing test file to copy for its style and fixtures: {{pattern_test_file}} - Cases I already worry about: {{known_cases}} Work in this order: 1. Before reading the implementation closely, turn the description above into a numbered list of rules the function must follow, including what it should do with empty, missing, duplicate and out-of-range input. Show me this list first. Tests written from the code tend to repeat its bugs, which is why the list comes from the description. 2. Write tests for each rule: at least one normal case and the boundary values, with each test checking one behavior and named after it, such as rejects_discount_above_fifty_percent. 3. Run the tests. Constraints: - Do not change the function or any other source file. This task only adds tests. - When a test fails, do not change the test to match the code. Keep it, mark it with the framework's expected-failure marker and a comment starting "Suspected bug:", and report it. - No network calls, real clocks, unseeded random values or state shared between tests. Use the fixtures the project already has, and add no new test dependencies. - Put the tests where the project keeps them, named like the pattern file, for example tests/test_pricing.py or pricing.test.ts. Done when: - Every rule in your list has at least one test. - {{test_command}} passes, apart from the tests you marked as suspected bugs, and every existing test still passes. - git diff shows changes to test files only. Report: a table with the columns Rule, Test name, Result (pass or suspected bug), then the last 20 lines of the test output. Verify the result by running the command yourself. If the description is silent or ambiguous on a case, do not decide what the right behavior is. List it under Spec gaps with the question to ask, and leave that case untested.
Variables
- {{function_path}}
- The function and its file, for example "calculate_invoice_total in billing/invoices.py".
- {{intended_behavior}}
- What it should do, from the spec, ticket, docstring or business rules, as written.
- {{test_command}}
- How tests run, for example "pytest tests/billing" or "npm test".
- {{pattern_test_file}}
- An existing test file to copy, for example "tests/test_tax.py".
- {{known_cases}}
- Cases you already suspect, for example "orders with a 100 percent discount". Write "none" if none.
Why it works
- Background facts. Rules are drawn from the spec before the code is read closely, so the tests check what the function should do rather than echo what it does.
- What to avoid. Source files stay untouched and failing tests are kept and marked as suspected bugs, never bent to match the code.
- If unsure. Where the spec is silent, the case goes on a Spec gaps list with a question, instead of the agent deciding the right answer for you.