AI Hallucinations in Software Testing: Why AI Output Must Be Checked

AI can invent a Playwright method, a business rule or a test result, and present it with complete confidence. This is called a hallucination. Finding it is exactly the kind of work testers are good at. In this lesson you will learn where AI hallucinations in software testing appear and how to catch them.

Advertisement

📖 What You’ll Learn

  • What a hallucination is and why it happens
  • The six most common hallucinations in QA work
  • How to reduce them with better prompts
  • A 5-step checklist for reviewing any AI output

💡 What Is an AI Hallucination?

Explain Like I’m 5: Hallucination

Imagine: Ask a small child, “Where does the moon sleep?” The child may say, “In a big cloud bed!” The child is not lying. The child just filled the gap with a story.

What it really means: AI sometimes makes up an answer that sounds right but is not true.

In testing: AI shows you a Playwright method that does not exist.

A hallucination is AI output that sounds believable but is false or unsupported. It happens because an LLM generates likely text and does not automatically check facts. When it lacks information, it may fill the gap instead of saying it does not know.

Treat AI like a new team member

A new teammate can be fast and helpful, but you would still review their first test cases. Give AI output the same review, every time.


🔍 Six Hallucinations Testers Meet

TypeExampleHow to catch it
Invented code methodA Playwright method that does not existCheck the official docs, then run the code
Invented locator#login-btn when the page has no such IDInspect the real page
Invented business rule“Password must include a symbol” when the story never says soCompare with the requirement
Invented packageAn npm install command for a package that does not existCheck the package registry before installing
Wrong expected resultA wrong tax value in a test caseCalculate it yourself or ask the product owner
False claim of work“I ran the tests and all passed” when nothing was runAsk for evidence, and run them yourself

Security warning

Attackers can publish malicious packages using names that AI tools tend to invent. Never install a package just because AI suggested it. Check that it exists, who maintains it and whether it is widely used.

Explain Like I’m 5: Fake Packages

Imagine: Children keep asking for a toy that does not exist. A bad person hears this, makes a box with that name and puts something harmful inside.

What it really means: AI can invent a package name, and an attacker can then publish a harmful package with that name.

In testing: Check a package before you install it.


🧩 Why This Matters More in Testing

Explain Like I’m 5: A Wrong Answer Key

Imagine: A teacher marks homework using a wrong answer key. A wrong answer gets a gold star, and nobody notices.

What it really means: A test only compares the app with the expected result it was given.

In testing: If AI writes a wrong expected result, a bug can pass as green.

A hallucination in a test can be worse than no test at all. Suppose AI writes a test with a wrong expected result. Your suite goes green, the defect reaches production, and everyone believes the feature was verified. A passing test only proves that the code matched the expectation someone wrote, and that expectation may be wrong.


🛠️ How to Reduce Hallucinations

You can reduce hallucinations, but you cannot remove them completely.

  • Provide the source: paste the requirement instead of describing it from memory.
  • Limit the scope: tell the AI to use only the information you supplied.
  • Allow “I don’t know”: ask it to list assumptions and missing information.
  • Ask where it came from: have each test case point to its requirement line.
  • Use real page details: give the AI actual HTML or labels so it does not guess locators. You can practise on the Automation Practice Page.

📌 The 5-Step Review Checklist

Explain Like I’m 5: Reviewing AI Output

Imagine: Before you eat an apple from a new basket, you look at it and wash it.

What it really means: Always check AI’s work before you use it.

In testing: Run these 5 checks on every AI answer.

Use this for anything AI produces.

  1. Source: can every statement be traced to a requirement or document?
  2. Reality: do the screens, fields, APIs and methods actually exist?
  3. Expected results: are they correct according to the business rule, and not just plausible?
  4. Coverage: what did the AI miss, such as negative, boundary, role or data cases?
  5. Execution: have you actually run the code or steps yourself?

🌍 Real-Life Example: Reviewing an AI Test Case

Requirement: “A user can apply one coupon per order. The coupon gives 10% off.”

AI-generated test case: “Apply SAVE10 to an order of 1000. Expected: the total is 900, and free shipping is applied.”

Run the checklist. The 900 total is correct for a 1000 order. Free shipping appears nowhere in the requirement, so it is invented. The coupon name is also assumed. A reviewer should remove the shipping claim, confirm a valid coupon code, and add the missing case of applying a second coupon.


🧪 Try It Yourself

Test the AI the way you would test an application.

  1. Open a new chat and paste the prompt below. The method named in it does not exist.
  2. See whether the AI explains how to use it, or tells you it does not exist.
  3. Check the official Playwright Page API documentation.
  4. If the AI caught the problem, ask about a realistic invented option such as a made-up setting in playwright.config.ts, and compare again.
  5. Record which answers were correct and how confident each one sounded.

📋 Ready-to-Copy Prompt

Show me how to use page.waitForMagicElement() in Playwright with
TypeScript. Give me a short example for a login page.

Then use this prompt whenever you want AI to review a set of test cases:

Review the test cases below against the requirement.

Rules:
- Use only the requirement text as the source of truth.
- For each test case, quote the requirement line it is based on.
- Flag any step or expected result that is not supported by the
  requirement as "UNSUPPORTED".
- List missing positive, negative and boundary scenarios.
- If information is missing, say so. Do not guess.

Requirement:
[paste requirement]

Test cases:
[paste test cases]

⚠️ Common Mistakes

  • Believing an answer because it is detailed and confident
  • Asking the same AI “Are you sure?” and treating its reply as proof
  • Running AI-suggested install commands without checking them
  • Changing an expected result just to make a test pass
  • Skipping review because the AI output looks tidy

🎯 Key Takeaways

  • A hallucination is believable but false or unsupported output.
  • Hallucinations can be reduced with good context, but never fully removed.
  • A wrong expected result can create false confidence, which is a serious risk.
  • Use the 5-step review checklist on every AI output.

🎤 Interview Questions

1. What is an AI hallucination?

Model answer: It is output that sounds believable but is false or not supported by the available information, such as a Playwright method that does not exist. It happens because the model generates likely text and does not automatically verify facts.

2. How do you verify AI-generated test cases?

Model answer: I trace each test case back to the requirement and remove unsupported steps. I confirm that the screens and fields exist, check each expected result against the business rule, and add missing negative and boundary cases. For automation, I also run the code.

3. How can you reduce hallucinations when using AI for testing?

Model answer: I give it the actual requirement and real page details, tell it to use only that information, and ask it to list assumptions and unknowns. Asking for traceability also makes unsupported content easy to spot. These steps reduce the risk, but I still review the output.

4. Can a passing AI-generated test still be a bad test?

Model answer: Yes. It may assert the wrong expected result, check something trivial or never reach the real behaviour. A pass only means the application matched that assertion, so I review what the test really verifies. One useful check is to break the behaviour on purpose and confirm the test fails.

5. What risk comes from AI-suggested packages?

Model answer: AI can suggest a package name that does not exist, and an attacker could register that name with malicious code. I verify that the package exists, is maintained and is approved by my team before installing it.


📝 Assignment

Ask an AI assistant to write 10 test cases for a feature of the Dummy E-commerce Website. Apply the 5-step checklist, and create a table showing each problem you found, its hallucination type and your correction.


❓ FAQ

Will newer AI models stop hallucinating?

Newer models can improve, but you should not assume hallucinations will disappear. Verification remains part of responsible AI use.

Can I ask a second AI to check the first one?

Yes, a second review can find extra issues, but it is another opinion and not proof. The requirement, official documentation and real execution remain your sources of truth.


🚀 Next Steps

Well done on finishing this lesson. Complete the assignment, then continue with Will AI Replace Software Testers? How the QA Role Is Changing.