Community post
Use AI to Draft Tests, Then Challenge the Tests
By Liam · Published · 2 min read
Editorial standards and correctionsAI-assisted testingsoftware testingunit testsboundary testinginvalid input testingmutation thinkingAI coding prompts
Prompt AI for boundary and invalid-input tests, then check whether the tests would catch a real defect.
AI can write tests that pass while missing the failure you care about. A test suite is useful only if it distinguishes correct code from plausible wrong code.
A small bank of repeatable tasks from A Tiny Evaluation Set for Your Favorite Coding Prompt lets you test whether the test-writing prompt improves.
Ask for tests from the contract
For
speed_bonus(seconds), the contract says 100 at 0, subtract 2 per second, floor at 0, and reject negative inputs. I ask:
Write tests for the contract below. Cover a normal value, the floor boundary, a value past the floor, and negative input. Do not infer extra requirements. For each test, name the rule it checks.
Now I can see whether every rule has a test. But coverage labels are not proof.Challenge the tests with a wrong implementation
Imagine a buggy function that returns
100 - 2 * seconds without the floor. Would the generated tests fail it? If not, add a test past the boundary. Imagine another that sorts input in place despite promising a new list. Would the tests detect mutation? If not, add an original-input check.
This is a simple form of mutation thinking: introduce a plausible defect mentally and ask whether a test catches it. You can use tools to automate such checks later, but the habit starts on paper.Run and inspect the suite
Do not accept tests solely because they look sensible. Run them against the real code. Read each assertion and make sure it checks the intended value, not merely that the function returns something. The Python standard library’s unittest documentation is a reliable reference for test structure and assertions.
Try it: Ask AI for five tests for a small function. Write one deliberately wrong implementation on paper. If the tests would still pass, revise the prompt to target the missed rule.
Keep learning: A Tiny Evaluation Set for Your Favorite Coding Prompt, Debugging With AI: Reproduce the Bug Before Requesting a Fix, and How to Test a Prompt on More Than One Example.
About the author
Liam
Coder and gamer. I test prompts, share what works, and show how to improve AI results for code and creative projects.
View Liam's public profileComments (0)
Loading comments…
Keep exploring
Related from Prompt Engineering Lab
Privacy Checks Before You Paste Anything Into AI
Remove credentials, private identifiers, and unnecessary personal data before using AI tools; preserve the task without exposing the source.
How to Prompt Across Models Without Pretending They Work the Same
Keep the task and success criteria stable while checking each AI provider’s current model-specific guidance.
Use AI for Brainstorming, Then Narrow With Real Criteria
A two-stage AI brainstorming method: generate genuinely different options, then filter by time, cost, audience, and testability.