AI Test Case Generation: Know What It Read Before You Trust It
AI-generated test cases go wrong where their input goes quiet. Follow one feature through a requirement, the code and the running app, then review any case.
AI test case generation is an AI model, usually a large language model (LLM), drafting the setup, steps and expected result of a test from something it can read. That something is a written requirement, the source code or the running app. Each input decides what the AI model can know, and so how its cases go wrong.
If you’ve just been handed a “generate test cases” button, the first batch will look complete whether it is or not. Knowing its input tells you what the batch left out and who has to confirm each expected result before a case counts.
What you’ll learn
- The three inputs AI generates test cases from
- How each input fails, on one password reset feature
- Who has to check the expected result for each input
- An eight-point review for any generated test case
The Input Decides What the Cases Miss
Test case generation is the part of AI testing that decides what gets checked, so its input shapes everything after it. A model can only test what its input tells it, almost like a new tester handed one document on day one and nothing else. Give the tester the spec and they test the spec. Give them the code and they test the code. Sit them in front of the app and they test what they see.
Other inputs fold into these three. A user story, an API spec or a mock-up is a requirement by another name, and a recorded user session is the running app played back.
| Input | What the cases cover | How they fail | Who checks the expected result |
|---|---|---|---|
| Requirement | The behavior someone wrote down | Silent on what the document never said | The requirement’s owner |
| Code | The branches the model reads | Treats today’s behavior, bugs included, as correct | An engineer with the spec open |
| Running app | The flows the agent reaches | Records what the screen did, not what it should do | Anyone who knows the product |
The worked example is invented, like every name and number in it. The requirement reads: “A user who forgets their password can request a reset link by email. The link expires after 30 minutes.”
From a Requirement: Only What Was Written Down
Hand the requirement to a model and the cases come back tidy, one per sentence:
- Request a link: A registered user enters their email and receives a reset link.
- Use the link: The user opens it within 30 minutes, sets a new password and signs in with it.
- Expired link: The user opens it after 30 minutes and sees an expiry message.
Each case traces to a line, which is the strength of this input. The requirement’s owner can check every case against the sentence it came from.
Now ask what the requirement never said. What does an unregistered email see? Does the old link die when the user requests a second one? Does a used link work twice? The model either skips those cases or writes one with an expected result it made up. Neither shows on the page as a gap.
So read a requirement-based set for what’s missing before you read what’s there. A case with an invented expected result is a question for the requirement’s owner, and the answer belongs in the requirement before it belongs in the test.
From the Code: Today’s Behavior, Bugs Included
Hand the model the reset handler instead. It reads the branches, so it can find cases the requirement missed, such as a malformed token, a token for a deleted account or a database timeout. Then it meets this line:
const RESET_LINK_TTL_SECONDS = 30 * 60 * 60; // 30 minutes
The comment says 30 minutes. The arithmetic says 30 hours. A model writing tests from this code asserts that a link opened after two hours still works, and that test passes. It now defends the bug. We walked through the same failure on a shipping-cost function, with three models and 56 test suites, in can you trust AI-generated tests.
Generating from the code makes sense when you want tests that lock in what the code does today, for example before a refactor. Meta’s TestGen-LLM improves existing human-written tests rather than writing them from nothing. On Instagram’s Reels and Stories, 75% of its test cases built correctly, 57% passed reliably and 25% increased coverage. Those are unit tests measured against a suite that already existed. They don’t tell you whether the expected results were right.
TLDR: code-based cases are strong on branches and blind on intent.
From the Running App: Someone Has to Judge the Result
Point an agent at the running app and it does what a curious user does. It walks the reset flow from “Forgot password” to the link in the inbox, then it can keep going into paths nobody wrote down:
- Two requests: It asks for a second link and tries the first one again.
- Already signed in: It opens a reset link in a browser already signed in to another account.
- Back button: It presses Back after setting the new password and lands on the form again.
None of those were in the requirement, and the code doesn’t flag them as special. This input can reach flows that cross two features and belong to neither team’s spec.
The catch sits in the expected result. The agent records what the screen did, and here the first link kept working after the second request. Is that right? The app can’t say. A product owner can, because the case is written in screens and taps instead of code. This input hands the call to whoever knows the product, without asking them to read the implementation.
How to Review a Generated Test Case
Every review starts by asking where the expected result came from. A requirement line is a source. Code is a source with a caveat. A recorded screen is a source someone has to approve. A blank is a guess. Then run the rest of the list:
- Name the source of the expected result. Write it beside the case as a requirement line, a function or an observed screen.
- Trace both ways. Every case points at a requirement or a flow, and every requirement has at least one case.
- State the preconditions. Account state, test data and environment are written down, not implied.
- One behavior per case. A case that checks three things fails for three reasons and explains none.
- Make the result observable. “The user sees an expiry message” passes review. “Reset works correctly” doesn’t.
- Look for the negative cases. Used twice, wrong account, empty field. In the requirement example above, only the expired link got a case.
- Merge duplicates. Two cases with different wording and the same steps are one case, and keeping both inflates the count.
- Send gaps upstream. A case you couldn’t confirm is a missing line in the requirement. Fix it there.
Volume makes the early review urgent. One team we work with asked a coding agent to explore everything possible on one page of their app, and it came back with about a thousand test cases. Nobody confirms a thousand expected results one at a time.
TestRail’s generator takes your product requirements and suggests titles and descriptions first, so you can edit them before it writes steps and expected results. Run points 1, 2 and 7 at that stage, while a case is one line long.
Which Tools Generate From Which Input
AI-powered test automation tools differ most in which input they read, so sort them by input before you compare features.
| Input | Where it lives | What you get |
|---|---|---|
| Requirement | Test management tools and Jira apps | Manual test cases with steps and expected results |
| Code | Coding assistants in the editor; in-house tools like Meta’s TestGen-LLM | Unit tests in your repository |
| Running app | Agents that explore the app; Playwright’s planner agent | End-to-end tests of user flows |
A case generated from a requirement usually lands as a manual test case. It stays manual until someone scripts it in one of the test automation tools the team already runs.
Some tools mix inputs. Playwright’s test agents, added in version 1.56, include a planner that walks the app and writes its findings up as a Markdown test plan, with a product requirement document as optional context. A generator then turns that plan into Playwright test files, and a healer edits a failing test, expected values included, or marks it skipped. The files, and their locators, live in your repository from then on.
Generation is also only the first step of test automation. A generated case that never runs, or that breaks on the next redesign, adds to the review queue and catches nothing.
Let Pie Explore the App, Then Read What It Wrote
We built Pie on the third input, and built it AI-native, with our agents doing the tapping and clicking a tester would do. As an agentic testing platform, Pie explores the running app on web, iOS or Android and drafts a test for every flow it gets to, so a flow that never made it into a requirement can still get a case. What it hands back is made for the review above:
- Plain-English tests: Each test is a list of steps plus the checks Pie makes at the end. Whoever owns the feature can read and edit these human-readable test cases without opening the code.
- Pie Chat: Describe a flow in a sentence and get a test for it.
- Version history: Every saved edit becomes a version that records what changed and who changed it. You can also see which version of a test a run used.
So the product owner from the reset example can rule on whether the first link should keep working after a second request, and the judgment stays with your team. That ruling is the part of AI QA no generator does for you.
Pick the Input Before the Tool
All three inputs return tidy cases. The input decides which cases are missing and which expected results are guesses, so choose it before you compare tools.
Take one feature you shipped last month and generate from the input you actually have for it. Put the eight-point review in front of the first ten cases before you ask for the next hundred.
See Tests Generated From Your App
Bring one feature and see the test cases Pie drafts for it.