Resources / Code generation
How to test AI-generated code (and let the AI test it too)
A practical testing approach for code written by AI: realistic requests, edge cases, draft environments and letting the model fix what fails.
AI-written code usually works for the example in the prompt. Bugs hide in the inputs nobody mentioned. Testing is how you find them before your users do.
Test against a draft, not production
Every change should deploy somewhere callable but not live. Run real requests against it. Only promote when it behaves.
Start with realistic requests
Call the endpoint the way your app will: real-looking ids, real payload shapes, real headers. Check the status code, the response body and how long it took.
Then try the edges
The questions that catch most AI bugs:
- Missing fields: what if
emailisn't sent? - Wrong types: a string where a number belongs.
- Empty values: an empty list, an empty string, zero.
- Large inputs: a 5 MB body, 10,000 items.
- Upstream failure: what if the third-party API times out or returns 500?
- Repeats: the same webhook delivered twice.
Expect clear 4xx errors for bad input, never a 500.
Let the model test itself
Models are good at writing test requests for their own code — ask for "five requests that should fail and five that should succeed". Run them, and hand failures back with the actual error. The fix loop is fast when the model sees real output.
Keep the log
A request log with inputs, outputs and errors turns "it doesn't work" into a concrete failing case. It's also your regression suite: replay last week's requests after a change.
Watch it in production
Some bugs only show up with real traffic. Track error rates per endpoint and alert on spikes, so you hear about problems before users report them.
In Wisp
The assistant tests each endpoint after writing it and fixes what fails. You can call any draft with ?test, and every request is logged with its input, output and console output.
Build it with Wisp — describe an API, get it live.