Notes
Three modes
Most assistants work in three modes. Ask: questions and explanations, no edits, like why does this locator match three cells. Plan: it proposes which files to change and how, and you approve before anything is written. Agent: it edits files and runs commands in a loop. For test code, ask often, plan before anything larger than one test, and use agent mode where you can review a diff and rerun the suite.
- ask: "why does this locator match three cells?" no edits
- plan: "which files would you change to add a coupon test?" you approve first
- agent: edits files and runs commands in a loop
- most editors and coding tools offer all three
The experiment
The experiment. We asked a local model, llama three point two, for pytest tests of ShopRung's cart quantity rules. Once with a vague prompt, and once with context: the real endpoints, how to log in, the test accounts, product ids and stock, the error codes and the cart requirements. Three runs each, six files, and we ran every file against ShopRung exactly as written.
- model: llama3.2:3b, local
- vague: "Write pytest tests for the cart quantity limit of my online shop's REST API."
- with context: the endpoints, login and accounts, product ids and stock, error codes, rules CART-1 to CART-6
- each file run against ShopRung
Vague
With the vague prompt, none of the three files ran. Two imported a module called your API that does not exist, one used a library that was not installed. They posted to slash cart on a placeholder website, invented a quantity limit of twenty, and expected status four twenty nine. That is a test suite for an imaginary shop. The model filled every gap with a guess.
from your_api import client → No module named 'your_api' (2 of 3 files) import requests → not installed POST /cart, https://your-api- url.com/cart invented: a limit of 20, status 429 for too many
With context
With context, the tests used the real endpoints, accounts and product ids. Still, none ran as written. One imported a web framework it never used and that was not installed. One created an HTTP client with no base address. One used a fixture it never defined, and a config attribute that the httpx client does not have. Two of three also called a logout endpoint that the API description never mentioned.
real endpoints, accounts and product ids: yes file 1: import fastapi → No module named 'fastapi' file 2: Client() with no base URL → UnsupportedProtocol file 3: fixture 'client' not found; client.config[...] 2 of 3 invented /api/auth/logout
Fix it up
We took the best file and fixed it like a reviewer would. Removing the unused import made all nine tests fail with four oh one: it logged in, but never sent the token. Sending the token and resetting the data left four passing and five failing. The failures were the model's: it expected quantity ten to be refused, though the rule allows ten; four hundred instead of the documented four oh nine; and endpoints that do not exist.
remove the unused import: 9 failed: assert 401 == 200 (token fetched, never sent) send the token, reset data: 4 passed, 5 failed qty 10 → expected 400 (CART-2: 10 is allowed) stock 0 → expected 400 (409) logout, PATCH on an empty cart
Give it context
Context is what turns a guess into a draft. Give it your existing conftest and one good test as the pattern, so it reuses your fixtures instead of inventing them. Give it the API description and the rules with ids, and your library versions. Ask for one small test at a time, and a plan before a larger change. When a test fails, paste the real error output: that is the context it is missing.
- your existing conftest.py and one good test, as the pattern
- the API description and the rules with ids
- the exact library versions
- one small test at a time
- the real error output when it fails
- ask for a plan before code
Who is wrong?
When the generated tests fail, decide who is wrong before you ask the assistant to fix anything. Quantity ten returning two hundred is correct: the test is wrong. Out of stock returning four oh nine matches the documentation: the test is wrong. But on another day, the app will be wrong. If you let the assistant fix failures by copying whatever the app returned, you turn its bugs into your expectations. Decide with the requirement.
- assert 200 == 400 at qty 10: the test is wrong (CART-2)
- assert 409 == 400 at stock 0: the test is wrong (the API doc says 409)
- never let the assistant "fix" a failure by copying what the app returned
- decide with the requirement
Common mistakes
Mistakes. Asking without context and getting tests for an imaginary API. Accepting code you have not run. Fixing failures by telling the assistant to make them pass. Asking for a whole suite in one go, which is too much to review. Not checking new imports and endpoints, which are where inventions hide. And pasting secrets or real customer data into a chat.
- no context: tests for an imaginary API
- accepting code you did not run
- "make it pass" as the fix
- big files in one go
- new imports and endpoints nobody checked
- secrets or real data in chat
Say it like this
In the interview: as a pair, in small steps. I give it our conftest, a sample test, the API description and the rules, ask for a plan, then one test at a time, and I run everything. In a trial, none of six generated test files ran as written, and the best one, once fixed, still expected the wrong status codes. So every expected value is decided from the requirements, by me.
- "As a pair, in small steps. I
- give it our conftest, a sample
- test, the API and the rules, ask
- for a plan, then one test at a time. I run everything: in a trial none of six generated
- files ran as written, and the fixed one still had wrong
- expectations. I decide every expected value from the rules."