Skip to content
QAcademy — QAcademy

Prompt engineering ·

How to Generate Test Cases with AI: A Reliable Method from User Story to Reviewed Suite

By The QAcademy team

Illustration for the article "How to Generate Test Cases with AI"

Pasting a user story into a chatbot and typing "generate the test cases" takes ten seconds. What comes back looks like finished work: twenty neatly formatted rows, clear titles, expected results. The trouble starts when you review it. One acceptance criterion has no test at all, two cases check the same thing, and a third verifies a business rule nobody ever wrote down.

You can generate test cases with AI and save real time, as long as you treat the output as a draft and keep ownership of coverage. This article walks through a four-step method that works with any LLM, applied to a complete user story.

Why "generate the test cases" is not enough

An LLM produces the most probable continuation of what you give it. With a one-line request, it fills the gaps with whatever is common elsewhere: generic password rules, the "usual" behavior of an e-commerce cart, test cases it has seen a thousand times. For a tester, that has three consequences:

  • Coverage is not under control. Nothing forces the model to address every acceptance criterion or to apply a test technique.
  • Inventions look plausible. A test case for a rule that does not exist has exactly the same shape as a valid one. That is a hallucination, and you only spot it by comparing against the test basis.
  • Output varies. Run the same prompt twice and you get a different list. Without traceability, you cannot tell what was gained or lost.

Published research points the same way. In a 2024 study, researchers at IIIT Delhi had ChatGPT generate system test cases from requirements specifications: about 87% of the generated cases were valid, the remaining 13% were not applicable or redundant, and 15% of the valid cases had not been considered by the developers (Bhatia et al., 2024). The value is real, but roughly one case in eight was noise in their setting, and someone has to sort it out.

The 4-step method

The core idea is to split the task into steps (prompt chaining) and check each step before moving on. Here is the fictional user story we will use.

US-214: Apply a promo code As a signed-in customer, I want to apply a promo code to my cart so that I get a discount.

  • AC1: a valid code applies its percentage discount to the subtotal, excluding shipping.
  • AC2: a code is only accepted if the subtotal is greater than or equal to $50.00.
  • AC3: an expired code is rejected with the message "This code has expired".
  • AC4: one code per order; entering a second code replaces the first after the customer confirms.
  • AC5: code entry is case-insensitive.

Step 1: have the story analyzed before generating anything

Do not ask for test cases yet. Ask for ambiguities and open questions first. On US-214, a decent model will raise questions such as: does the discount apply before or after other promotions? What happens if the customer declines the replacement in AC4? Is the $50.00 threshold checked before or after the discount?

Send those questions to the Product Owner. Until they are answered, any test case that "settles" them is the model's assumption, not a requirement. This step often pays off the most: it finds defects in the test basis before a single test is written.

Step 2: generate cases with a structured prompt

Once the story is clarified, generate with a structured prompt: role, context, instructions, input data, constraints, output format.

ROLE
You are an experienced tester specializing in test design for e-commerce applications.

CONTEXT
We are testing the cart "promo code" feature (US-214) at system level,
through the web UI. The PO's answers to the open questions are included
in the input data.

INSTRUCTIONS
Generate functional test cases covering every acceptance criterion.
Apply boundary value analysis to the AC2 threshold and equivalence
partitioning to codes (valid, expired, unknown, different letter case).

INPUT DATA
<US-214 and its 5 acceptance criteria>
<PO answers to the step 1 questions>

CONSTRAINTS
- Each test case lists the criterion or criteria it covers (AC1 to AC5).
- Do not add any rule that is not in the input data. If a case seems
  useful but relies on an assumption, put it in a separate list
  "Assumptions to confirm".
- Expected results must be observable and precise (amount, exact message).
- Fictional test data only.

OUTPUT FORMAT
Table: ID | Title | Preconditions | Steps | Data | Expected result
| Criteria | Technique
Then the list "Assumptions to confirm".

Three constraints do most of the work: the Criteria column, which makes every case traceable; the ban on invented rules, with a dedicated place for assumptions; and the demand for an observable expected result, which kills "the system behaves correctly". Naming the test design techniques you expect also stops the model from choosing for you. A 2025 industry study follows the same logic (identify applicable techniques first, then generate cases technique by technique) and reports results that vary widely from one requirements set to another (Masuda et al., 2025): the method helps, but you still have to measure.

Step 3: check coverage criterion by criterion

In a separate prompt, ask for a coverage matrix: one row per acceptance criterion, the cases that cover it, and what is left uncovered. Then check it yourself. The model's matrix is a helper, not evidence: it can mark a criterion as covered when no case actually exercises it.

Here is a realistic output extract, with comments:

ID Title Data Expected result Criteria
TC-01 Discount excludes shipping Subtotal $80.00, shipping $5.90, code SAVE10 (10%) Discount $8.00, total $77.90 AC1
TC-03 Threshold reached Subtotal $50.00 Code rejected, threshold message AC2
TC-04 Threshold not reached Subtotal $49.99 Code rejected, threshold message AC2
TC-06 Lowercase code "save10" Code accepted AC5
TC-07 Code not combinable with sale items Sale item + SAVE10 Code rejected AC1

A human review finds three problems in two minutes:

  • TC-03 is a reasoning error. "Greater than or equal to $50.00" means $50.00 is accepted. The model flipped the boundary logic. On a boundary case, that is precisely the mistake that lets a defect through.
  • TC-07 is a hallucination. No criterion mentions sale items. The rule is plausible (plenty of shops apply it), but it is not in US-214. Keep it and you will test, or even get someone to build, behavior nobody asked for.
  • AC4 does not appear anywhere. Replacing a code with customer confirmation is the trickiest behavior in the story, and the model either forgot it or pushed it to the end of the list.

This is the heart of the method: check coverage from criteria to cases, never the other way round. Starting from the cases gives a false sense of safety, because every case displays a criterion.

Step 4: refine, then convert to your target format

Fix the output by hand, or feed the gaps back to the model ("AC4 is not covered by any case; TC-07 relies on a rule that is not in the input, remove it"). Only then convert to your target format:

  • Gherkin: give the model two or three scenarios written by your team (few-shot prompting). It will pick up your vocabulary, granularity and naming conventions.
  • End-to-end procedures: ask the model to help you write the prompt that will generate them (meta-prompting), then review that prompt before you use it.

Keep the final prompt and the corrections you made. That is the start of a team prompt library, and the baseline for comparing two prompt versions on the same story.

Common pitfalls

  • Judging by volume. Forty redundant cases are not better than twelve good ones. Measure coverage of criteria and partitions, not row count.
  • Vague expected results. "Code is applied" does not let anyone decide pass or fail. Demand amounts, exact messages, states.
  • Sloppy boundaries. Models happily propose $49 and $51 instead of $49.99 and $50.00. Check every boundary against the requirement.
  • Happy-path bias. Outputs tend to be rich in passing cases, thin on error cases and almost empty on non-functional testing. Ask for them explicitly if your test strategy calls for them.
  • Real data in the prompt. A user story may contain customer names, log excerpts or confidential rules. Use fictional or anonymized data only, and a tool your organization has approved.
  • Assuming the output is stable. Rerun the prompt and the list changes. That non-determinism is normal, but it means you must freeze the version you keep and store it with the prompt that produced it.

What to remember for the CT-GenAI exam

Generating test cases with AI sits at the center of chapter 2 of the ISTQB® CT-GenAI v1.1 syllabus, the longest chapter in the program (365 of 815 training minutes).

  • LO 2.1.1 and 2.1.2: the six-part prompt structure and the three core techniques (prompt chaining, few-shot prompting, meta-prompting). Know which one fits which need.
  • LO 2.2.1 and 2.2.2 (K3, apply): using generative AI for test analysis (test conditions, defects in the test basis, coverage) and then for test design and implementation. Hands-on objectives HO-2.2.2a and HO-2.2.2b follow the workflow above closely: generation, per-criterion coverage check, a meta prompt for end-to-end procedures, then Gherkin with few-shot examples.
  • LO 2.2.5: choosing the right technique for the context. A long task that can be checked step by step calls for chaining; a tightly specified format calls for examples.
  • LO 2.3.1 and 2.3.2: evaluation metrics (accuracy, precision, recall, relevance, diversity and others) and iterative prompt refinement, including A/B testing of prompts.
  • LO 3.1.2: recognizing a hallucination or a reasoning error in an output, like TC-07 and TC-03 above.

The CT-GenAI certification guide places these objectives in the wider program, and the exam guide covers the exam format.

FAQ

Can AI replace a tester's test design work?

No. It speeds up the first draft and suggests cases you might have missed, but choosing techniques, checking coverage and validating expected results remain human responsibilities.

Which format should I ask for: a table or Gherkin?

Start with a table that has a traceability column: it is easier to review and check. Move to Gherkin once the cases are validated, with a few of your team's scenarios as examples in the prompt.

Do I need a specialized tool, or is a chatbot enough?

A chatbot is enough to apply the method, provided the data you send is allowed to leave your environment. A tool integrated with your test management mainly adds access to context (linked requirements, existing cases) and automatic traceability. Human review is needed either way.

Next step

If this method makes sense to you, check where you stand across the whole syllabus: the free diagnostic asks 10 questions in 5 minutes and shows which chapters to work on first.

Sources

  • ISTQB®, Certified Tester – Testing with Generative AI (CT-GenAI), syllabus v1.1 and exam format: istqb.org
  • ISTQB®, Certified Tester Specialist Level Syllabus – Testing with Generative AI, v1.1, sections 2.1, 2.2.1, 2.2.2, 2.3 and 3.1.
  • S. Bhatia, T. Gandhi, D. Kumar, P. Jalote, System Test Case Design from Requirements Specifications: Insights and Challenges of Using ChatGPT, 2024: arxiv.org
  • S. Masuda et al., Generating High-Level Test Cases from Requirements using LLM: An Industry Study, 2025: arxiv.org

Take the next step

You have just read. Now see where you stand: 10 questions, your score chapter by chapter, free and without signing up.

Take the free test (5 min)

Already decided to practise?

One-off payment, no subscription, refunded within 14 days if it is not for you.

Get the new articles by email

At most one email a week: the new QAcademy articles on software testing and quality. Free, unsubscribe in one click.

5 minutes · free · no sign-up

Before you go: where do you stand?

10 questions in the exam format, about 5 minutes: your score by chapter and your gap to the pass mark.

5 minutes · free · no sign-up