DEV Community

Your AI-generated tests are grading their own homework

Dimitris Kyrkos on November 19, 2026

Ask an AI assistant to "write tests for this endpoint" and you will get tests. Lots of them. They compile, they pass, coverage goes up, and the PR ...
Collapse
 
alexcodebytes profile image
Oleksandr •

This is a really important distinction. I've seen AI-generated tests focus heavily on confirming that the implementation works as written, rather than challenging the assumptions behind it. I especially like the idea of writing invariants before showing the model the implementation. That changes the whole perspective from "does this code work?" to "can this code violate something it must never violate?" Mutation testing is a great addition too. A green test suite means very little if it can't catch the failures that actually matter.

Collapse
 
cyclopt_dimitrisk profile image
Dimitris Kyrkos •

Exactly. The key is that the model shouldn't be the one deciding what correctness looks like based on the implementation it's testing. I think that's where a lot of the false confidence comes from. You end up with a large suite that validates assumptions nobody explicitly agreed on. Starting with invariants gives you an independent reference point, and mutation testing helps verify that the tests actually enforce it.

Collapse
 
alexcodebytes profile image
Oleksandr •

Exactly. A test suite can have impressive coverage and still be completely wrong if the expected behavior was derived from the same assumptions as the implementation. Invariants give you an independent standard, while mutation testing checks whether the suite can actually detect violations rather than just execute the code.

I think the distinction between testing that code runs and testing that it behaves correctly is easy to overlook, especially when AI generates both sides. The real question is whether the tests can prove the implementation wrong.

Thread Thread
 
cyclopt_dimitrisk profile image
Dimitris Kyrkos •

That's a good way to put it. And I think the tricky part is that having AI generate both the implementation and the tests makes this even easier to miss. Everything can look consistent because both are based on the same assumptions. That's why I wouldn't judge the quality of a test suite by coverage or test count, but by the failures it can actually catch.

Thread Thread
 
alexcodebytes profile image
Oleksandr •

Exactly. AI can produce an implementation and a perfectly passing test suite that reinforce the same flawed assumption, making the whole thing look more reliable than it actually is. More tests don't necessarily mean more independent verification.

I think the real value of a test is proving that the system can fail when something is genuinely wrong, especially in cases the original implementation didn't anticipate. Tests based on independent requirements, adversarial inputs, or unexpected edge cases become much more valuable here.

The interesting question is how we preserve that independence when AI is involved in writing almost everything, including the tests meant to challenge its own code.

Thread Thread
 
cyclopt_dimitrisk profile image
Dimitris Kyrkos •

I think the best way is to keep the source of truth outside the implementation. Have a human define the security properties and expected behavior first, then let AI help translate those into tests. It can still generate most of the test cases, but it shouldn't get to redefine what correctness means along the way. Otherwise we're just automating the same blind spots.

Collapse
 
innokentyb profile image
Kent Bodrov •

The empty-response gap is a good example of why the oracle needs to cover the whole user outcome, not just one security property. I’d add a state-changing scenario too: a user from tenant A attempts to update tenant B’s invoice, then an independent read as tenant B confirms its amount and status are unchanged. A 403 alone would miss a handler that writes before returning the error. Would you keep that state read in the same acceptance test or as a separate invariant?

Collapse
 
cyclopt_dimitrisk profile image
Dimitris Kyrkos •

I'd probably keep it as a separate invariant, but make it part of the same broader acceptance test flow. The important thing is to verify the actual state after the unauthorized attempt, not just trust the response code. A 403 looks reassuring, but if the write already happened, the security boundary has still been broken. This is another case where checking side effects matters just as much as checking the response.

Collapse
 
maciek_chmura_building profile image
Maciek Chmura •

One gap in the parametrized test: returned <= {client.tenant_id} also passes when the endpoint returns nothing. A route that throws a 500, or a refactor that filters out every row, stays green for all five callers. I'd add two asserts next to it. The same-tenant user gets back exactly the invoices seeded for that tenant, and anonymous and expired_token get a 401 instead of an empty list. Then the suite fails in both directions, leaking too much and returning too little. For the serializer case, do you keep an explicit allowlist of response fields per role?

Collapse
 
cyclopt_dimitrisk profile image
Dimitris Kyrkos •

Good catch. You're right, the subset assertion alone doesn't protect against returning nothing. We need to test both sides: what must never be exposed and what must actually be returned. Otherwise we risk having tests that pass simply because the endpoint stopped working.

On the serializer side, yes, I'd favor an explicit allowlist per role. It's much safer than checking a few expected fields because newly added fields won't silently become part of the API response. That's exactly the kind of regression these tests should catch.

Collapse
 
paullovelace profile image
Paul Lovelace •

failure mode 1 is the one that hit home for me — seeding one tenant and calling it a test for a multi-tenant endpoint. I'd have written that exact test and felt good about it, right up until someone deleted the filter and nothing went red

Collapse
 
cyclopt_dimitrisk profile image
Dimitris Kyrkos •

I think a lot of us would have written that test and been happy with the coverage too. The problem is that without a second tenant, you're never really testing tenant isolation. It's a good example of how a test can look perfectly reasonable while missing the exact failure it's supposed to catch.

Collapse
 
anp2network profile image
ANP2 Network •

A mutation score tells you how the suite reacted to the code changes it was given. An assertion can still accept invalid results that none of those mutants happen to produce, because nothing in the code is wrong. The acceptance set of the checker is just too wide.

So mutate the output directly. Feed the assertion layer an identity mutant that returns the input unchanged, plus a fabricated result that belongs to another tenant, and require the checker to reject each one. You can run those checks without invoking the producer at all.

On a public signed log of agent task deliveries, an automated verifier passed all 10 deliveries that simply returned the input unchanged, and 47 of 48 deliveries whose own output field said no translation was done. Mutating the producer would have missed that defect. The checker was the bug.

Do you ever run your assertions directly against fabricated bad outputs, or only against mutated code?

Collapse
 
cyclopt_dimitrisk profile image
Dimitris Kyrkos •

That's a really good point. I think we tend to focus so much on whether the implementation mutations get caught that we forget the assertions themselves need testing. Fabricated bad outputs are a great way to challenge that independently, especially when the producer can return something plausible but completely invalid. I'd definitely include this as another layer of verification. Testing the code is one thing, testing whether the checker can recognize a bad result is another.

Collapse
 
yonka profile image
Yonka Ivanova •

Very true! My next article will be about that as well. All tests green, but I noticed something which didn't work and started doubting the tests.

Collapse
 
cyclopt_dimitrisk profile image
Dimitris Kyrkos •

That's exactly the kind of thing that makes this tricky. When all tests are green, it's easy to assume the implementation is fine. But sometimes the tests are just confirming the same assumptions as the code. Looking forward to your article, curious what you found!