Skip to content
QAcademy — QAcademy

AI risks ·

LLM Hallucinations in Software Testing: How to Spot, Detect and Reduce Them

By The QAcademy team

Illustration for the article "LLM Hallucinations in Software Testing"

An AI-generated test script that calls a method that does not exist announces itself on the first run: it crashes. The real danger lies in the mistakes that do not crash. A test case that checks a rule nobody asked for, a prioritized test suite that ignores a dependency, a test data set where every customer is called John Smith. All of these survive a quick review because they are well written and plausible.

This article shows, with tester-level examples, what LLM hallucinations look like in software testing, how to detect them systematically and how to make them less frequent. It separates three defects that the ISTQB® CT-GenAI syllabus covers together: hallucinations, reasoning errors and biases.

Three different defects, three ways to look for them

All three produce wrong output, but for different reasons, and no single check catches them all.

Defect What happens Typical symptom in testware
Hallucination The model produces incorrect or irrelevant content and presents it confidently. Test case for an acceptance criterion that does not exist, call to a non-existent API, reference to an invented standard.
Reasoning error The model gets the logic wrong: a condition, cause and effect, a calculation, a sequence of steps. Inverted boundary, prioritization that breaks a dependency, wrong total in an estimate.
Bias The model reproduces imbalances from its training data. Test data that is entirely US-centric, no non-functional tests, happy path over-represented.

NIST calls the first one "confabulation": confidently stated but erroneous or false content that may mislead users. OWASP lists the topic as LLM09 ("Misinformation") in its Top 10 for LLM Applications and stresses the aggravating factor: overreliance, when users stop checking.

What hallucinations look like in testware

The phantom acceptance criterion

The "Reset my password" user story has three criteria: link sent by email, expiry after 30 minutes, single use. The model generates ten test cases, including this one:

TC-09 Lockout after 3 attempts
Preconditions: active account
Steps: enter a wrong reset code 3 times
Expected result: the account is locked for 15 minutes

Nothing in the story mentions lockout or a code. The case is believable because many applications behave that way. Keep it, and the team will test unspecified behavior and may raise a defect against something that is not one.

The API that does not exist

Ask for a Playwright script for an Angular application and you may get:

await page.goto('/claims/new');
await page.waitForAngular();          // not part of the Playwright API
await page.getByLabel('Amount').fill('1200');

waitForAngular() belongs to another tool (Protractor): the model blended two similar APIs. Here, execution warns you straight away. Dependencies are sneakier. A study presented at USENIX Security 2025 analyzed 576,000 code samples from 16 LLMs and found that the average share of hallucinated (non-existent) packages was at least 5.2% for commercial models and 21.7% for open-source models (Spracklen et al., 2025). Attackers can publish a malicious package under a commonly hallucinated name, so installing without checking hands them the keys. If you are choosing a framework, see our Playwright vs Selenium vs Cypress comparison.

What a reasoning error looks like

Tasks that require combining several rules are the most exposed: planning, estimation, prioritization. Here is an example with four test cases from a claims module (fictional data):

Case Risk Depends on
TC-A Create a claim High none
TC-B Attach a supporting document Medium TC-A
TC-C Approve the settlement High TC-B
TC-D Export the PDF summary Low none

Instruction: order by descending risk while respecting dependencies. Answer received: "A, C, B, D, because A and C are high risk". Wrong: C cannot run before B, which it depends on. The correct order is A, B, C, D. The model applied the first rule and dropped the second.

This is not a one-off. Apple researchers showed that LLM performance on mathematical reasoning drops when only the numbers in a problem change, and that adding a single clause that seems relevant but does not affect the answer can cut performance by up to 65% (Mirzadeh et al., 2024). The lesson for testers: a rambling user story full of irrelevant detail also degrades the model's reasoning.

What bias looks like

Ask for twenty fictional customers to test a sign-up form. Typical biases:

  • only English-sounding names, nothing with an accent, apostrophe or hyphen ("Benoît", "N'Diaye", "Ben Salah-Martin");
  • US-style addresses and phone numbers, dates in month/day order;
  • no very long names, no non-Latin characters, no multi-line addresses.

Those are exactly the inputs that break forms. Bias in LLMs is well documented in research (Gallegos et al., 2024) and comes from the training data: a model trained mostly on English-language content tends to default to English-speaking profiles. The same logic applies to test types: without explicit instructions, outputs often over-represent passing functional cases and neglect accessibility, performance and security. You will not see bias in a single test case; you see it when you compare the whole set against your test strategy and the partitions you expect (see our guide to test design techniques).

Detect: compare with the test basis, not with your gut feeling

The central habit is cross-verification: every item the model produces must trace back to a source (requirement, acceptance criterion, documentation, known system behavior). In practice:

  1. Require traceability in the prompt (see our method to generate test cases with AI). Each case cites the ID of the criterion it covers. A case with no source, or with a source that does not say what the case checks, is suspect. This can be partly automated: extract the cited IDs and compare them with the real list.
  2. Run consistency checks. Do cases contradict each other? Are amounts consistent across cases? Rerunning the same prompt, or giving it to a second model, and comparing the outputs exposes unstable items: anything that shows up only once deserves a second look.
  3. Validate the logic. For a prioritization or an estimate, redo the calculation or check each constraint one by one. On a reasoning task, the question is not "is this convincing?" but "is every rule respected?".
  4. Test the output. A script runs, compiles and passes the linter. A package name is checked in the registry before anything is installed.
  5. Bring in the domain expert when the rule is subtle: a claims specialist will spot an implausible deductible calculation in one read.
  6. Look for bias at set level: distribution of test types, partitions and data profiles, compared with the test strategy.

How deep you go depends on risk. Exploratory test ideas can be skimmed; test data feeding a regulatory regression campaign deserves a full check.

Reduce: better prompts, shorter steps

Hallucinations and reasoning errors show up mostly when the prompt is poorly designed or context is missing. The levers, roughly in order of effort:

  • Provide complete context with a structured prompt, and explicitly allow the model to say it does not know.
  • Split the task with prompt chaining, checking each intermediate result before feeding it forward.
  • Use clear input formats: numbered criteria and tables rather than a scanned PDF or a pasted chat thread.
  • Pick a model suited to the task, and compare outputs from several models when the stakes justify it.
  • Ground the model in your own documents with retrieval-augmented generation (RAG), or specialize it with fine-tuning: both are covered in chapter 4 of the syllabus.

Here are constraints worth adding to your generation prompts:

CONSTRAINTS
- Use only the input data provided.
- For every item you produce, give the source ID (AC-x, REQ-x).
- If required information is missing, write [UNKNOWN] and state the
  question to ask instead of making an assumption.
- List separately any suggestion that does not follow directly from
  the input data, under the heading "Out of scope, to confirm".

One point that is often misunderstood: lowering the temperature or setting a random seed reduces the variability of answers, not their falseness. A model can repeat the same hallucination with perfect consistency. These settings make results more reproducible, and therefore easier to check, especially when the checking is automated.

What to remember for the CT-GenAI exam

Section 3.1 of the CT-GenAI v1.1 syllabus covers this topic through four learning objectives:

  • LO 3.1.1 (K1): recall the definitions of the three defects. Be able to tell an invention (hallucination) from a logic fault (reasoning error) and from an imbalance inherited from training data (bias).
  • LO 3.1.2 (K3): identify these defects in a given output. Expect to analyze a testware extract and name the problem, as in the examples above.
  • LO 3.1.3 (K2): summarize mitigation techniques (complete context, splitting the task, clear formats, choosing and comparing models).
  • LO 3.1.4 (K1): techniques against non-determinism (temperature, random seed) and their limits.

Hands-on objective HO-3.1.2a has you provoke hallucinations (such as invented criteria) with at least two LLMs; HO-3.1.2b has you trigger a reasoning error on a test planning task (estimation, prioritization). The topic connects to section 2.3.2 (output analysis) and to chapter 4 (RAG, fine-tuning). The CT-GenAI certification guide and the exam guide give you the full picture.

FAQ

Can hallucinations be eliminated entirely?

No. You can make them less frequent and, above all, catch them, but they stem from how LLMs work: they generate probable text, not verified text. Human verification remains necessary.

Does a reasoning model solve the logic error problem?

It may do better on tasks with several constraints, but that does not remove the need to check. Always compare the result with the exact expected result, for example by recomputing a prioritization.

Is asking the LLM to review its own output enough?

It helps catch omissions, but it is not an independent check: the model can confirm its own mistake. Keep the comparison with the test basis and, where possible, a second model or a human reviewer.

Next step

Recognizing a defect in AI output is a skill you can practice. The free diagnostic (10 questions, 5 minutes) shows where you stand on this chapter and the others.

Sources

  • ISTQB®, Certified Tester – Testing with Generative AI (CT-GenAI), syllabus v1.1: istqb.org
  • ISTQB®, Certified Tester Specialist Level Syllabus – Testing with Generative AI, v1.1, section 3.1.
  • NIST, AI 600-1, Artificial Intelligence Risk Management Framework: Generative Artificial Intelligence Profile, July 2024: nvlpubs.nist.gov
  • OWASP, LLM09:2025 Misinformation, Top 10 for LLM Applications: genai.owasp.org
  • J. Spracklen et al., We Have a Package for You! A Comprehensive Analysis of Package Hallucinations by Code Generating LLMs, USENIX Security 2025: usenix.org
  • I. Mirzadeh et al., GSM-Symbolic: Understanding the Limitations of Mathematical Reasoning in Large Language Models, 2024: arxiv.org
  • I. O. Gallegos et al., Bias and Fairness in Large Language Models: A Survey, Computational Linguistics, 2024: 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