When AI-Generated Tests Pass but the Product Fails
Passing tests do not necessarily establish correct software behavior. Through recent research and a controlled JavaScript demonstration, this article examines how incorrect test oracles, missing boundary conditions and weak assertions can allow defects to survive automated verification.
On this page
A developer asks an AI coding agent to implement a business requirement and generate the corresponding unit tests. The agent completes both tasks, executes the test suite and reports that every test passes.
The implementation is accepted.
Several weeks later, a customer encounters behavior that contradicts the original requirement. The engineering team investigates, discovers the defect and corrects the implementation. Unexpectedly, one of the existing tests now fails.
The test was protecting the defect.
This illustrative scenario exposes a fundamental problem in software testing: a test can be executable, repeatable and technically correct as a test while enforcing behavior that is incorrect from a business perspective.
Artificial intelligence did not introduce this problem. Developers have always been capable of writing incomplete tests, incorrect assertions and tests that reproduce implementation assumptions.
However, AI-assisted development creates circumstances in which the problem deserves particular attention. When the same agent generates both the implementation and its verification, an incorrect interpretation of a requirement can be reproduced across both artifacts.
The resulting agreement between code and tests may create confidence without establishing correctness.
Testing Implementation Versus Testing Intent
A software test generally requires two elements: a mechanism for exercising the software and a mechanism for determining whether the observed behavior is acceptable.
The second element is commonly described as a test oracle. It provides the expected outcome against which actual behavior is evaluated.
A test oracle might be derived from a business rule, a mathematical calculation, an authoritative specification, a reference implementation or an invariant that must remain true across different operations.
The distinction becomes important when tests are generated directly from existing source code.
Consider an online store with the following delivery policy:
- Standard delivery costs $7 for orders below $100.
- Standard delivery is free for orders of $100 or more.
- Express delivery always costs $15.
Amounts are calculated using integer cents, and input validation is handled separately.
An implementation might look like this:
function shippingCents(subtotal, method) {
if (method === "express") return 1500;
return subtotal > 10000 ? 0 : 700;
}
The implementation contains a boundary defect. Customers with a merchandise subtotal of exactly $100 are incorrectly charged for standard delivery.
Now consider three automated assertions:
assert.equal(shippingCents(5000, "standard"), 700);
assert.equal(shippingCents(15000, "standard"), 0);
assert.equal(shippingCents(15000, "express"), 1500);
All three pass.
The tests exercise both delivery methods and all three possible return paths. They also contain meaningful assertions rather than merely checking whether the function executes.
Nevertheless, the implementation contradicts the requirement.
The missing condition is the precise boundary at which standard delivery becomes free.
A requirement-derived assertion would expose the defect immediately:
assert.equal(shippingCents(10000, "standard"), 0);
A more concerning situation arises if the existing implementation is treated as the source of truth when generating expectations:
assert.equal(shippingCents(10000, "standard"), 700);
This assertion passes on the defective implementation but fails when the comparison operator is corrected.
The difference between these two tests is not their technical sophistication. It is the authority from which their expected results were derived.
One protects the business requirement. The other protects the existing behavior.
How AI-Generated Tests Can Preserve Incorrect Behavior
Automatic test generation from existing implementations has legitimate applications. Characterization tests, for example, can help developers document the behavior of a legacy system before restructuring it.
But documenting observed behavior and establishing intended correctness are different activities.
When an AI model is asked to generate tests for an existing function, the function itself may provide substantial information about its apparent purpose. If independent requirements are unavailable or insufficiently emphasized, implementation behavior can become the basis for expected outcomes.
This is particularly problematic when the implementation already contains defects.
A 2026 preprint by Charoosaei, Richter and Papadakis examines this risk through generated regression tests associated with 145 pull requests from SciPy, Qiskit and pandas. The authors distinguish tests that expose faults from tests that preserve faulty behavior, demonstrating how incorrectly generated expectations can persist across subsequent software revisions [1].
The significance of this problem extends beyond a single inaccurate test. Once an incorrect expectation becomes part of an accepted regression suite, later developers may interpret it as an established behavioral contract.
Correcting the original defect can then appear to introduce a regression.
However, the research evidence does not justify dismissing AI-generated test oracles altogether. A 2025 study by Molinelli and colleagues found that generated oracles achieved mutation-testing performance comparable to developer-written oracles within their evaluated dataset [2].
These findings are not necessarily contradictory. They examine different evaluation conditions and aspects of test quality.
AI-generated tests can provide substantial value. The important qualification is that their usefulness depends on what they assert, the evidence supporting those assertions and their demonstrated ability to distinguish acceptable behavior from defects.
The relevant question is therefore not whether a test was written by a developer or generated by a model. It is whether the test provides reliable evidence about the behavior it claims to protect.
Weak Assertions, Excessive Mocking and Missing Failure Conditions
Incorrect expected outcomes represent only one way in which a passing test suite can become misleading.
Several other patterns deserve attention when reviewing automatically generated tests.
Assertions that establish too little
A test might confirm that an API returns HTTP 200, that a function produces a non-null result or that a page contains a particular element.
These checks may be useful, but their evidential value depends on the requirement.
For example, confirming that an order endpoint returns a successful response does not necessarily establish that the correct order was created, that its monetary values are accurate or that the transaction belongs to the authorized customer.
The strength of an assertion should correspond to the behavior being claimed.
A test that establishes only the existence of a result should not be interpreted as evidence of the correctness of that result.
Excessive dependence on mocked behavior
Test doubles allow software components to be evaluated without requiring every external dependency to be available.
They are particularly useful when interacting with payment providers, notification services, databases or other systems whose real execution would be expensive, slow or inappropriate.
However, a test environment can become detached from the production contract if every dependency is configured to produce the desired response.
Consider a checkout test in which the payment provider always approves the transaction, the inventory service always confirms availability and the order repository always accepts the record.
The test may establish how the application behaves under those assumptions. It does not establish whether the application correctly handles declined payments, inventory conflicts or persistence failures.
Martin Fowler’s discussion of test doubles and verification approaches highlights the trade-offs between observing system state and verifying interactions with collaborators [3].
The problem is not mocking itself. It is allowing simulated assumptions to replace the behavior that needs to be investigated.
Missing negative paths
Many important software requirements describe what must not happen.
An unauthorized user must not access another customer’s order. A rejected payment must not produce a confirmed paid transaction. A cancelled booking must not continue to occupy available capacity.
Testing only the permitted operation leaves these restrictions unexamined.
A useful test suite should therefore represent both the behavior the system must allow and the behavior it must prevent.
This becomes especially important when a feature can appear operational while violating a less visible business, security or data-integrity constraint.
Establishing an Independent Test Oracle
The word independent does not necessarily mean that a different person, organization or AI model must write the tests.
It means that the expected behavior should not be derived exclusively from the implementation being evaluated.
A second AI agent examining the same defective code does not automatically provide an independent oracle. Both agents may inherit the same missing requirement or incorrect interpretation.
Independence can instead be established through an authoritative source that determines what the software should do.
For the delivery example, this source is the agreed delivery policy.
From that policy, a reviewer can construct a decision table before inspecting the implementation:
| Merchandise subtotal | Delivery method | Expected fee |
|---|---|---|
| $99.99 | Standard | $7 |
| $100.00 | Standard | $0 |
| $100.01 | Standard | $0 |
| $99.99 | Express | $15 |
| $100.00 | Express | $15 |
| $100.01 | Express | $15 |
This table captures two distinct business rules: the inclusive threshold for free standard delivery and the unconditional express-delivery charge.
The test implementation becomes a translation of those rules into executable assertions.
More complex systems may require additional forms of independent reasoning:
- State-transition models for orders, appointments and payment lifecycles.
- Decision tables for combinations of eligibility rules and constraints.
- Authoritative reference calculations for prices, discounts and financial operations.
- Invariants for data integrity, permissions and consistency.
- Independently prepared acceptance scenarios for complete user journeys.
The appropriate oracle depends on the requirement.
If the underlying requirement is ambiguous, the expected result should not be invented simply to complete a test. The ambiguity should remain visible until an authorized decision establishes the intended behavior.
Evaluating Tests Through Mutation and Controlled Fault Injection
A passing test suite demonstrates agreement between its assertions and the evaluated implementation.
A stronger question is whether the same suite would fail if the implementation were deliberately changed to violate a requirement.
Mutation testing provides one approach to answering that question. It introduces controlled changes into program behavior and evaluates whether existing tests detect them. A mutation is commonly described as killed when the test suite exposes the introduced change and surviving when it does not [4].
This can reveal weaknesses that ordinary execution and coverage measurements leave unresolved.
A controlled teaching demonstration
To examine this distinction, a small JavaScript demonstration was constructed around the delivery policy introduced earlier.
Two test suites were evaluated:
- Baseline suite: the three original assertions covering ordinary delivery scenarios.
- Strengthened suite: the baseline assertions plus six additional boundary and delivery-method assertions derived from the decision table.
Both suites were executed against a correct implementation and five deliberately defective variants.
The defects were selected to represent violations of the stated delivery policy, including incorrect boundaries, incorrect charges and improperly applied delivery benefits.
The original AI-assisted demonstration was executed using Node.js 22.16.0 without external dependencies. The table records that execution. A later isolated rerun of the unchanged original script under Node.js 24.22.3 was reported to reproduce both suites’ results and the incorrect-assertion example. The source is retained privately and is not distributed with this article.
| Implementation | Baseline tests | Strengthened tests |
|---|---|---|
| Correct implementation | Pass | Pass |
| M1: Free delivery requires more than $100 | Pass | Fail |
| M2: Free delivery begins prematurely at $99 | Pass | Fail |
| M3: Express delivery becomes free from $100 | Fail | Fail |
| M4: Express delivery costs only $7 below $100 | Pass | Fail |
| M5: Standard delivery incorrectly costs $9 | Fail | Fail |
Both suites accept the correct implementation.
However, the baseline suite detects only two of the five deliberately introduced faults. Three defective implementations pass every baseline assertion.
The strengthened suite detects all five.
Figure: Reported teaching demonstration; detection results for five selected defects, not a general comparison of AI-generated and human-written tests.
A separate assertion that incorrectly expects a $7 standard delivery charge at exactly $100 was also evaluated. It passes on the strict-threshold mutant and fails on the correct implementation, illustrating how a test can actively preserve an existing defect.
These results demonstrate two different risks:
- A test suite may fail to detect incorrect behavior because an important condition is missing.
- A test may reject correct behavior because its expected result is wrong.
The distinction is important because increasing test coverage alone does not necessarily resolve the second problem.
What the results establish
This is a deliberately constructed teaching example, not a controlled comparison of human-written and AI-generated test suites.
The nine strengthened assertions are not evidence of a universal testing advantage, and detecting five selected faults does not establish that the implementation is free from all defects.
The demonstration establishes a narrower but useful point: tests can execute successfully and exercise relevant code paths while failing to protect an explicit business rule.
Larger empirical studies require independently selected faults, representative systems, controlled comparison conditions and appropriate statistical analysis.
Mutation results also require interpretation. Some generated mutations are behaviorally equivalent to the original implementation, while others affect properties outside the intended testing scope. A surviving mutation should therefore be investigated rather than automatically treated as evidence of inadequate testing.
The objective is not to achieve an impressive mutation score. It is to identify important behavior for which the current verification remains insufficient.
Recent research has also explored using mutation-testing feedback to improve LLM-based test generation itself. Wang and colleagues’ 2026 study of mutation-guided test generation provides an example of integrating fault-detection feedback into the generation process [5].
This suggests a constructive direction: using AI not only to produce tests, but also to help investigate and improve their demonstrated effectiveness.
A Verification Workflow for AI-Generated Tests
AI-generated tests should be treated as proposed verification artifacts rather than automatically accepted evidence of correctness.
The following workflow is a practical approach for reviewing generated tests.
1. Establish the behavioral authority
Identify the requirement, business policy, specification or invariant from which the expected behavior should be derived.
If no authoritative interpretation exists, clarify the requirement before accepting assertions that depend on it.
2. Define important scenarios independently
Identify normal behavior, boundary conditions, prohibited operations and relevant failure states.
For changes to existing software, also identify the previously accepted behaviors that must remain unchanged.
3. Review the generated assertions
Examine whether each assertion actually establishes the behavior described by its test.
Pay particular attention to expected values copied from existing implementation logic, overly permissive assertions and test descriptions that promise more than their checks establish.
4. Challenge the tests with incorrect behavior
Introduce representative defects in an isolated testing environment and determine whether the tests detect them.
For regression tests associated with a specific defect, verify that the test fails on the known faulty revision and passes after the correction, where that comparison is feasible.
Then assess whether additional plausible faulty implementations can still pass.
5. Check integration boundaries
Identify which dependencies have been replaced with test doubles and which assumptions those replacements introduce.
Use proportionate integration or acceptance testing to investigate behavior that isolated unit tests cannot establish.
6. Preserve the meaning of the evidence
Report what the tests demonstrate, what remains unverified and which assumptions limit the conclusion.
A test suite that passes on the evaluated implementation should not be described as proving complete correctness.
This workflow need not become an expensive process for every minor change.
The appropriate depth depends on the consequences of incorrect behavior, the complexity of the requirement and the confidence already established by existing verification.
For a critical financial rule, authorization mechanism or state transition, challenging the tests against plausible defects may be considerably more valuable than generating additional assertions for ordinary scenarios.
Tests Must Be Capable of Exposing Incorrect Behavior
The value of automated testing is not that it produces a green result.
A valuable regression test protects an established expectation. A valuable acceptance test connects software behavior to an agreed requirement. A valuable negative-path test demonstrates that an important prohibited operation remains prohibited.
AI can accelerate the creation of all three.
It can also accelerate the creation of tests that repeat incorrect assumptions, verify insignificant details or preserve defects as expected behavior.
The engineering responsibility remains the same regardless of how the tests were produced: establish the source of the expected behavior, assess the strength of the verification and investigate the limits of the available evidence.
A useful way to evaluate any important test is to ask two questions:
What incorrect behavior would cause this test to fail? And how do we know that its expected behavior is actually correct?
If those questions cannot be answered, a passing result provides less confidence than it appears to.
References
[1] Charoosaei, M., Richter, C., and Papadakis, M. On the Risks of using LLM-Generated Tests for Regression Testing. arXiv preprint, 2026. https://arxiv.org/abs/2610.11835
[2] Molinelli, D., Di Grazia, L., Martin-Lopez, A., Ernst, M. D., and Pezzè, M. Do LLMs Generate Useful Test Oracles? An Empirical Study with an Unbiased Dataset. IEEE/ACM International Conference on Automated Software Engineering (ASE), 2025. https://conf.researchr.org/details/ase-2025/ase-2025-papers/10/Do-LLMs-Generate-Useful-Test-Oracles-An-Empirical-Study-with-an-Unbiased-Dataset
[3] Fowler, M. Mocks Aren’t Stubs. 2007. https://martinfowler.com/articles/mocksArentStubs.html
[4] PIT Mutation Testing. Basic Concepts: Mutation Operators, Mutants and Equivalent Mutations. https://pitest.org/quickstart/basic_concepts/
[5] Wang, G., Xu, Q., Briand, L., and Liu, K. Mutation-Guided Unit Test Generation with a Large Language Model. IEEE Transactions on Software Engineering, vol. 52, no. 5, pp. 1657–1671, 2026. https://doi.org/10.1109/TSE.2026.3682975. University research record