DEV Community

Cover image for AI Generated Tests Are Passing And Still Lying To You
TheBitForge
TheBitForge

Posted on

AI Generated Tests Are Passing And Still Lying To You

Three weeks ago I watched a test suite go green while the feature underneath it was completely broken. Not partially broken. Not an edge case. The core function did not work at all, and every single test said everything was fine.

That moment stuck with me more than any AI coding failure I had seen before, because usually when AI writes bad code, something breaks loudly. This was different. The tests were confident. The tests were thorough looking. The tests were also testing almost nothing that mattered.

If you have been using AI to generate your test suites, you need to hear this before it happens to you too šŸ˜…

The trap nobody warns you about

Ask an AI to write tests for a function and it will happily produce fifteen of them in about ten seconds. They will look professional. Proper naming, proper structure, decent coverage numbers when you run the report. Everything about them signals quality.

The problem shows up when you actually read what they are asserting. A huge chunk of AI generated tests check that a function returns something, not that it returns the right something. They confirm a variable is not null, they confirm a request does not throw an error, they confirm an array has a length property. All technically true, all completely useless for catching the bug that actually ships.

I started calling this pattern the confidence gap. The gap between how safe your test suite makes you feel and how much protection it is actually giving you. And the scary part is that this gap does not show up in any dashboard. Your coverage percentage looks great. Your CI pipeline is green. Everyone in the standup assumes the feature is solid because the tests say so.

Why this happens and why it is not really the AI's fault

AI models are pattern matchers trained on an enormous pile of existing test code, and a lot of that existing test code is already shallow. Plenty of real world test suites written by real humans check the easy stuff and skip the hard stuff, because writing a test for an edge case takes actual thinking about what could go wrong, not just what the happy path looks like.

So when an AI generates tests, it is often reproducing the same shallow habits that already existed in the training data, just faster and with better formatting. It does not know your business logic. It does not know that a discount code should never stack with another discount code, or that a refund should never process twice for the same order. It knows what a test usually looks like, not what your specific feature actually needs to be true.

That distinction matters enormously and almost nobody talks about it when they are debating whether AI can replace testing work.

The three questions I now ask every AI written test

Before I trust any test an AI writes, I make it answer three things in my head, and honestly this takes less time than it sounds.

Would this test actually fail if the logic were wrong. Not if the code crashed, if the logic were subtly wrong. A test that only fails on crashes is not testing behavior, it is testing that the code compiles.

Does this test know what correct actually means for this specific feature. A generic assertion like checking something is truthy usually means the AI did not understand the business rule, it just wrote something that would pass.

What edge case would a tired human tester think of that this test completely ignores. Empty inputs, duplicate submissions, expired sessions, race conditions, weird timezones. AI rarely reaches for these unless you specifically ask.

If a test fails even one of those three questions, I do not delete it, I just do not trust it as my safety net. It becomes decoration, not protection.

The fix is boring and that is exactly why it works

Nobody wants to hear this part but the actual solution is not a clever tool or a smarter prompt. It is going back to something engineering teams have always known and just applying it faster now that AI does the typing.

Write the test cases yourself first, in plain language, before any code exists. What has to be true for this feature to be correct. What has to be false. What should never happen under any circumstance. Then let the AI turn those into actual test code. You are still moving fast, you are just moving fast with a map instead of hoping the road stays straight.

I also started deliberately breaking my own features on purpose and running the test suite against the broken version. If the tests still pass when the feature is obviously wrong, that test suite was never protecting anything, it was just theater with a green checkmark at the end.

This one habit alone has caught more real bugs for me in the last two months than any coverage tool ever did.

What this actually means for you

AI has not made testing less important, it has made bad testing easier to produce at scale and harder to notice, because the output looks so polished. A shallow test suite written by a human at least feels shaky when you read it. A shallow test suite written by AI looks like it came from a senior engineer, which is exactly what makes it dangerous.

The developers who are going to be fine in this new world are not the ones avoiding AI generated tests entirely, that ship has already sailed. They are the ones who stopped treating a passing test suite as proof of correctness and started treating it as a starting point that still needs their judgment on top.

Green does not mean safe anymore. It means the AI understood the shape of a test, not necessarily the truth of your feature. Read your tests the same way you would read a pull request from someone you have never worked with before. Trust nothing until you understand why it should pass, and you will catch the bugs that everyone else's dashboard is quietly hiding from them.

Follow & Read More

Read More šŸ‘‡

Zero-Click Search in 2026: 68% of Google Searches End Without a Click — And What Still Earns One — TopBlogs

SparkToro's 2026 data puts US zero-click search at 68.01%. What the number counts, which content it hurts, and what I changed in client accounts because of it.

favicon topblogs.online

Dario Amodei's "Pace the Frontier": What Anthropic's CEO Actually Said About Slowing AI Down — TopBlogs

Anthropic CEO Dario Amodei says frontier AI development needs to slow down. Here's what "pacing the frontier" means, why he changed his mind, and how Altman, Musk and Hassabis responded.

favicon topblogs.online

Google August 2026 Spam Update: What Actually Survived — TopBlogs

16.71% of top 10 rankings fell past position 100 in Google's August 2026 spam update. Here's what got hit, what survived, and why

favicon topblogs.online

We Killed Our Onboarding Checklist. Here's What Happened — TopBlogs

We cut our SaaS onboarding from 7 steps to 1 and nearly doubled trial-to-paid conversion. Here's exactly what changed, and what we got wrong first.

favicon topblogs.online

Top comments (4)

Collapse
 
jo-do profile image
Jo Do

Mutation testing is the cleanest way I know to measure this confidence gap. Deliberately change comparison operators, delete side effects, or replace returned values, then count which mutants survive. Coverage tells you the line ran; surviving mutants tell you the test had no opinion about whether the behavior was right. I would also keep the plain-language cases versioned beside the code so an agent cannot quietly rewrite both the implementation and its oracle in the same change.

Collapse
 
thebitforge profile image
TheBitForge

Honestly you just named the thing I was circling around the whole post without landing on it. Coverage tells you the line ran, mutants tell you whether anyone actually cared what it did. Two completely different questions and we've been reporting the wrong one for years šŸ˜…

But your second point is the one that got me. Versioning the plain-language cases next to the code is the guardrail I completely missed, because the failure I wrote about can still happen even with a decent spec. Agent changes the implementation, test goes red, agent helpfully "fixes" the test in the same commit, everything green again. Nobody notices. That's so much worse than the shallow assertion problem and it never shows up anywhere.

Curious how you run the mutation side in practice though. Is it fast enough to gate every PR for you, or more of a weekly audit thing? That's where I keep getting stuck once the suite gets big.

Collapse
 
sureshh profile image
Suresh Chaudhary

AI is adding to the work.

Collapse
 
thebitforge profile image
TheBitForge

Yeah, it shifts more than it removes. It takes the typing away and hands you review work instead, and review is the slower part. The trap is that it feels like time saved because the output appears instantly, so nobody counts the hour spent reading it properly afterward. Still worth it for me, but only if I actually do that reading.