An AI-Written Test Is a Mirror, Not a Gate
A test for a ten-percent discount on 1,000 cents should expect 900 cents. Suppose an implementation instead subtracts the number 10 directly and returns 990. A generated test that takes 990 from the running function and
A test for a ten-percent discount on 1,000 cents should expect 900 cents. Suppose an implementation instead subtracts the number 10 directly and returns 990. A generated test that takes 990 from the running function and records it as the expectation will happily protect the mistake.
The problem is the provenance of the expected value. A model can produce a perfectly useful test when it has the business rule and an example whose answer a reviewer can derive independently. A human can also write a useless test by copying the implementationβs answer.
Two examples, two different jobs
| Amount and percentage | Expected under the rule | Subtracting the percentage as cents |
|---|---|---|
| 1,000 cents at 10% | 900 | 990 |
| 500 cents at 0% | 500 | 500 |
Both implementations pass the zero-percent case. It checks a boundary, but it cannot distinguish these two behaviors. The first row can. These fixtures deliberately avoid fractional cents; the product owner still has to specify rounding, minimum prices and how multiple discounts interact.
For an AI-assisted review, hand the test writer the requirement and example before providing the implementation. Ask where each expectation comes from: a contract, a documented example, or an observation of legacy behavior. Keep characterization tests when preserving that behavior is the actual goal. Label them so reviewers can tell what kind of promise a failing assertion calls into question.
Then show the reviewer one plausible faulty implementation or prior revision and the precise assertion that detects it. A failed import or a timeout does not establish that the test distinguishes 900 from 990. If the requirement itself is unsettled, the valuable output is a product decision about the example. A larger generated suite cannot settle that question.
This article was created with AI assistance.
Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.