Dev.to AI 🤖 Ai 👁 0 📖 4 min read

Are AI-written tests really tests? What the research says, and what happened when we tested it

Your AI agent says "done". The tests are green. Some of those tests were written by the same agent, in the same session, looking at the same code. Are they tests? I went through the published work from the last three y

Are AI-written tests really tests? What the research says, and what happened when we tested it

Your AI agent says "done". The tests are green. Some of those tests were written by the same agent, in the same session, looking at the same code.

Are they tests?

I went through the published work from the last three years to find out, and then ran the best ideas on our own benchmark. Here is what I found, including the part that did not work.

When the model sees the code, it tests the code, not the task

The core problem has a name: the oracle problem. A test needs to know the right answer. When a model writes a test while looking at the implementation, it tends to write down what the code does, not what it should do.

  • Across 24 Java projects, LLMs were more likely to encode the code's actual behaviour than the expected behaviour (Konstantinou et al.).
  • On 145 merged pull requests in SciPy, Qiskit and pandas, 8–17% of LLM-written regression tests asserted the buggy behaviour. Only 2.4–4.8% revealed the bug (Charoosaei et al.).
  • Coverage says little: one generated suite reached 100% coverage with a 4% mutation score (MUTGEN).

And agents do not only write weak tests. On tasks made deliberately impossible, frontier models "passed" by cheating about half the time, and for Claude models over 79% of the cheating was editing the tests (ImpossibleBench).

So a green run proves the code does what the tests ask. It does not prove the change does what you asked.

Two rules that turn an AI-written test into evidence

The research points to two rules:

  1. Write the check from the task, blind to the change. A checker that never sees the new code cannot copy its bugs.
  2. A check only counts if it fails on the old code and passes on the new. A check that passes on both proves nothing about the change.

This is exactly how Apex verify works. It is a small open-source tool (Apache-2.0): a different model writes checks from your task, proves they fail on the old code, runs them on the new code, runs your project's own tests, and gives a verdict with evidence: READY, NOT READY or UNKNOWN.

Apex verify catching a wrong change with no API key

What it measured

200 AI-written changes to 23 real open-source libraries, each labelled right or wrong by the hidden tests of the library's real fix. No API key: the checker was the Claude Code I was already signed in to.

Wrong changes caught Right changes wrongly stopped
Apex verify 0.3.1, no key 106 of 107 16 of 93

One run, Gemini models wrote every change, and the whole thing reruns with one command. Details and raw results are in the repo.

The 16 false alarms are the open problem. Earlier it was 23. Reading every one of them showed a pattern: 8 came from the library's own old tests asserting exactly the behaviour the task asked to change (the task says .example.com should be accepted; an old test says it must throw). So 0.3.1 takes a second look: if the task text explicitly contradicts a failing old test (it must quote the sentence, and the quote is checked), the verdict is "update the test", not "not ready". That cut false alarms from 23 to 16 without letting a single wrong change through.

The idea from the papers that did not work

The most promising remaining idea in the literature was agreement: draft several independent sets of checks and block only when most of them fail. Papers like CodeT and Otter++ got real gains by choosing among samples.

We built it and measured it on the same 200 changes.

All three independent sets agreed on 101 of 107 blocks. The vote overturned two blocks: one false alarm saved, no wrong change let through. One in 93, for two extra model calls on every blocked change. It ships off by default (APEX_VOTE=1 turns it on).

Why so little? Because the remaining false alarms are not one bad draft. Every independent draft reads the task the same strict way. The task text is simply broader than the library's own tests. Voting cannot fix agreement.

Two earlier ideas failed the same way: a second draft that blocks if either fails, and a probe for behaviour the task did not ask to change. Both helped on small projects and only added false alarms on real libraries. They are written up in the repo too.

What I take from this

  • An AI-written test is evidence only when it was written blind to the change and has shown it can fail.
  • "More checks" is not the same as "better checks". Every extra way to block adds false alarms.
  • The honest frontier is the task text itself: when a task is broader than the project's tests, a careful checker will disagree with the project. Sometimes the checker is right.

Try it on a wrong change in five seconds, no key and no project:

npx --yes https://github.com/apex-engine-dev/apex-verify/releases/latest/download/apex-verify.tgz verify --demo

The code, the benchmark and the experiments that failed are all at github.com/apex-engine-dev/apex-verify. If you have a case where it gets it wrong, I want to see it.

📰 Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.