The strongest input to a test-writing prompt is a description of observable behavior. If you supply only an implementation and ask for tests, a model can reproduce the implementation's assumptions—including its bugs—in the expected values.
Write down what a caller should observe before requesting test code. Then ask for a test matrix, inspect its expected results, and only afterward ask for the smallest useful executable suite. This is a practical way to apply the principle in Google's Test Behavior, Not Implementation: tests should focus on the contract rather than incidental internal steps.
Make the contract specific enough to disagree with code
Consider a fictional price helper. Its contract is:
- Input price is a nonnegative integer number of cents.
- Discount percentage is an integer from 0 through 100.
- Compute the discount in cents by rounding down, then subtract it.
- Reject a negative price or a percentage outside the range with
ValueError. - Do not change the inputs.
This is an example contract, not a recommendation for every billing system. A real system may require different rounding or tax behavior. The point is to decide that policy before a model encodes it in tests.
Ask for the matrix first
Design tests for this behavior contract before writing test code.
Contract: [paste the agreed behavior, input domain, and errors]
Public entry point: [function or API name]
Runtime and test framework: [fill in]
Implementation, if available: [paste authorized code or say unavailable]
Return a table containing each input, independently calculated expected
result or error, the behavior it checks, and the plausible bug it would catch.
Include a normal case, boundaries, empty/zero cases where meaningful, and
invalid input. Identify ambiguous requirements instead of guessing.
Do not derive expected values by calling or copying the function under test.
Do not invent modules, fixtures, network services, or completed test runs.
Keep tests about observable behavior, not private helpers or call ordering.
For the example contract, a compact initial matrix is:
| Input: cents, percentage | Expected | Purpose |
|---|---|---|
1000, 15 | 850 | Ordinary discount |
1001, 15 | 851 | Discount rounds down to 150 cents |
0, 15 | 0 | Zero price |
1000, 0 | 1000 | No discount |
1000, 100 | 0 | Full discount |
-1, 15 | ValueError | Invalid price |
1000, 101 | ValueError | Invalid percentage |
The second row is particularly useful: 1001 * 15 // 100 is 150, so the result is 851. That expected value was calculated from the contract. It would distinguish this policy from rounding the final discounted price down, which would produce 850. Neither policy is universally correct; the agreed contract decides.
Then ask for the tests
Using the reviewed matrix above, write the smallest runnable tests in
[framework/version]. Use the supplied public entry point and existing project
fixtures only. Keep the expected values explicit and independent.
Add error assertions for the stated invalid cases. Explain any required
setup. Do not change the implementation, skip a failing test, or claim to
have run commands. Finish with the exact command a developer should run and
any assumptions that still need confirmation.
Run that command in the real project. Check that discovery actually found the tests and that a failure is not hidden by a broad exception handler. If a test fails, first decide whether it reveals an implementation defect, a wrong test, or an incomplete contract; do not automatically rewrite the expectation to match current output.
Check that the suite can detect a mistake
On a disposable local copy, introduce one plausible defect—for example, remove the percentage range check or change the rounding rule—and confirm that an appropriate test fails. Restore the original code immediately afterward. This checks a different question from whether the suite passes: can it notice a behavior change you care about?
Avoid a large batch of near-identical cases that all exercise the same path. Add cases when they distinguish a boundary, an error, or a regression. For stateful behavior, also ask what should remain unchanged after a failed operation.
Keep the reusable instruction small
Save the stable matrix-first method and supply the current contract and framework each time. Keep production data and proprietary examples out of a public template. The prompt-organization guide offers a way to separate those reusable instructions from changing context.
Use the free VineScribe workbook to keep your own testing prompt, then revise it when a missed boundary teaches you something. Saving a prompt does not run a test suite: the developer still checks the contract and executes the tests in the target project.
