QA Interview Hub · Knowledge base · Quizzes · Українська

QA Fundamentals › AI in testing

Risks of AI-generated tests and code

The main risk of AI tests is expectations derived from code, not from a requirement, so they pass and lock in a bug (the oracle problem). An invented method is visible at once, while the more dangerous mistakes leave everything green: no asserts, happy path only, fixed waits. The model gets the requirement, expectations are checked against it, and a test is proved able to fail by deliberately breaking the code.

QA Fundamentals · AI in testing

All 40 generated tests are green. Why is that not yet a reason to celebrate?

A developer asks AI to write tests for a module, gets forty cases, and all pass on the first run. Coverage seems good now. But a test that could not fail has proved nothing. This lesson is about how exactly AI tests lose value, how that differs from obvious mistakes such as an invented method, and how to check that a test really guards something.

How it works and why. A model has no source of knowledge about correct behaviour except what it sees. If only the code is in the context, it concludes from the code, that is, it builds a test that confirms the implementation. This is the oracle problem: a test needs an independent source of the expected result (a requirement, a specification, an agreement), and the code cannot be one. Other risks differ in danger. An invented library method or outdated syntax is visible at once: the test does not run. The dangerous mistakes are those after which everything is green: a test without assertions, a happy path only, expectations taken from the code, unstable waits that "work on my machine".

Where the expected result comes from

From the code

the test repeats the implementation

The expectation is computed from what the code does now. A bug in the code becomes "correct" behaviour and the test is green.

From the requirement

the test checks the rule

The expectation is written apart from the code. The boundary 100 from the requirement catches the comparison-sign bug.

Figure 1. The same bug under two ways of writing a test.

Example: a test that guards the bug. The implementation has a comparison-sign bug:

// Requirement: 10% discount for a total of 100 and above
export function applyDiscount(total: number): number {
  return total > 100 ? total * 0.9 : total; // bug: should be >=
}

Tests generated from the code alone:

test('applies discount', () => {
  expect(applyDiscount(100)).toBe(100); // mirrors the code
  expect(applyDiscount(200)).toBe(180);
});

Both pass, although by the requirement the first assertion is wrong: at 100 the discount must already apply. The test not only missed the bug, it fixed it in place: if someone corrects the code, this test fails and looks like a regression. Now a test written from the requirement:

test('discount starts at 100', () => {
  expect(applyDiscount(99.99)).toBe(99.99);
  expect(applyDiscount(100)).toBe(90); // the boundary from the requirement
  expect(applyDiscount(100.01)).toBeCloseTo(90.009);
});

It fails on the current code, and that is the right signal. A check that a test can fail at all is simple: break the code on purpose (flip a sign, remove a condition) and see whether the test notices. Mutation testing automates this, but a manual version is enough for a review.

Limits and alternatives. This does not mean "do not write tests with AI". It creates scaffolding, data and repeated checks well, and the expectations stay with you. Give the model the requirement and not only the code, and ask for cases beyond the happy path. For code already in production there is one more option: tests that capture current behaviour make sense as a refactoring safety net (characterization tests), but they should be named so and not confused with a check of correctness. Everything generated goes through the same code review, linter and CI as hand-written code.

Common mistakes.

  • Counting green tests as proof of quality: without checking that a test can fail, it only shows that the code and the test agree with each other.
  • Asking to "write tests" without giving requirements: the model infers rules from the code and the bug becomes the reference.
  • Missing tests with no assertions or with an always-true assertion (for example, checking that a value is defined).
  • Leaving fixed pauses and brittle selectors because it "works". Later they become flaky tests.
  • Pasting code and data with secrets or real users into the request: a leak risk, not only a quality one.

Check yourself

AI generated a test for a function that computes a fee: the expected value in it is 1.5 and the test is green. What is the first thing you check?

Answer

Where 1.5 came from: the requirement or the output of the code itself. If from the code, the test proves nothing. After that, break the formula and see whether the test fails.

Why is an AI-invented library method less dangerous than a test that always passes?

Answer

An invented method shows at once: the code does not compile or crashes on the first run, and you fix it. An always-passing test looks like coverage, and nobody learns that it guards nothing until a bug reaches production.

In an interview. Junior: I read and run AI tests, compare them with the requirements and check that a test fails when the feature is broken. I do not paste data and secrets into the request. Middle/Senior: The main risk is tests that derive expectations from the code and therefore fix bugs in place (the oracle problem). So I give the model the requirement and not only the code, check the expected values against the requirement and make a quick mutation check: I break the code and see whether the test notices. Separately I look for tests without assertions, happy-path-only tests and fixed waits. Generated code goes through the same review and CI, and responsibility for quality stays with me.

More articles in this chapter