AI in Testing: Use It Without Trusting It, and Test AI Features
Trusting AI output gives you tests that can't fail and an assistant that invents policy. Review every AI-written test by breaking the feature on purpose, keep agents out of the gate, and test AI features with eval sets run in CI.
Key takeaways
- Treat every AI-written test as a pull request from a capable junior who has never seen your system.
- Break the feature on purpose and run the AI-written test; if it still passes, it is not a test.
- Browser agents and self-healing locators can report success when a step failed, so keep them out of the blocking gate.
- Never paste secrets, tokens or customer data into an AI tool your company has not approved for them.
- Test an AI feature with a versioned eval set, a score per case and a pass threshold, run in CI like any other suite.
- Authorisation belongs in the tools and APIs the model calls, so a fooled model still cannot leak another customer's data.
Contents
FAQ
Can AI write my test cases?
It can draft them quickly, including cases you would miss. Give it the rules, name the technique, ask for open questions instead of assumptions, and check every expected result and boundary yourself.
How do you test a feature that gives a different answer every time?
Test its deterministic parts with normal assertions, and the generated answers with evals: a set of cases, a score for properties such as correct facts and refusals, and a pass-rate threshold for the suite.
What is prompt injection?
Input that makes a model ignore its instructions, typed by the user or hidden in content the model reads, such as a product review. It is the top risk in OWASP's 2025 list for LLM applications.
Sources
Only you and the owner see your answer and rating. Send private feedback
Enjoyed it? Support fx-blog with a coffee.
Related posts
Quality Gates in CI: Make Your Tests Block a Bad Merge
Tests that run only when someone remembers put the gate in a person. Run them in four CI tiers that each block the next, keep the commit gate under ten minutes, give every run fresh data, and quarantine flaky tests the same day.
Green Tests, Broken Checkout: The Checks Functional Tests Miss
A green functional suite can't see a renamed field, a slow peak, an open security hole or a form a keyboard can't finish. Add a Pact contract, a k6 test against an SLO, a ZAP baseline scan, and axe plus a keyboard pass.
Why Your UI Tests Flake, and the Fix for Web and Mobile
Flaky UI tests teach a team to ignore red. Fix the three usual causes: brittle locators, fixed sleeps and shared data. Use role and test-id locators, web-first assertions, API setup, Accessibility IDs on mobile, and same-day quarantine.
Comments
Oldest firstNo comments yet. Start the conversation.
Part 6 gave the ShopLite checkout a gate that blocks a bad merge, and left two questions. If an AI assistant drafted those tests, which ones can't fail? And how do you test the shopping assistant that now answers customers in its own words?
Asked for "a Playwright test that SAVE10 gives 10% off", an assistant wrote this, as the repo records it:
Part 4 opened on three lines of it. It runs and it passes, and it would also pass if the page said "Error".
The QA Skills Path, in seven parts:
Review AI tests like a junior's pull request
Treat each generated test as a pull request from a junior who has never seen your system. The one above breaks part 4's rules (no cart set up, brittle selectors, a fixed sleep) and adds an assertion that can't fail. The fixed version sets up 2 × Mug and expects
€54.00 + €4.99 shipping. The fastest review is to break the feature and run the test; mutation tools such as Stryker, PIT and mutmut do it at scale.For test design, give the model the rules, name the technique, and ask for open questions instead of guesses. Then check its boundaries. The repo names a common slip: rejecting €50.00 for
SAVE10because "from €50" was read as "over €50".Agents help explore; they don't gate
Playwright MCP gives an assistant a real browser: ask it to add two mugs, apply
SAVE10, drop to one mug and report the totals, and it re-runs BUG-311. But agents report what they think happened, sometimes claim success when a step failed, and take a different path each time. Check the trace, turn a useful run into a script, and keep agents out of the blocking gate.Self-healing locators fail quietly: if "Apply" disappears, the tool may click "Apply for credit" and pass.
Test the assistant with evals
Ask the assistant the same question twice and you get two answers; one may promise a discount that doesn't exist. Exact matches don't work, so you score properties of each answer across a set of cases:
The repo's runner checks each answer against these strings and fails below a 95% pass rate, so it drops into part 6's pipeline:
String checks are crude but cheap. Where wording varies too much, a second model can grade against a rubric, once it agrees with two people's labels. Pin the model version, or results change with no code change.
The model is not the security boundary
Prompt injection, input that makes the model ignore its instructions, is the top risk in OWASP's 2025 list for LLM applications. The repo's cases for the assistant include:
apply_discountwith values the user may not set.Try it
Save the runner from the repo's
testing-ai-features.mdasrun_evals.py, with the cases inevals/. Its stub assistant lets it run before you connect a model:What this means for your career is in Will AI Replace Testers? Make Your Judgment the Evidence.
That is the whole path. ShopLite went from six rules to a tiered gate and evals for its assistant. The repo goes deeper on every step.
Read this with your AI