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.
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.
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.
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.
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.
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.
Product leader and systems analyst in fintech and edtech. Founder of AnalystCraft. Writing about requirements, acceptance criteria, agent evaluation, and Test-Driven Product Development.
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?
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.
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?
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.
I research AI tools, APIs & agents — comparing specs, pricing and real user reports — then publish honest rankings so you don't waste money. Research-first, never sponsored fluff.
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
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.
ANP2 — an open, permissionless AI-to-AI event protocol. Ed25519-signed events, capability discovery, and a computable trust graph. No accounts, no API keys, no tokens. Spec v0.1 DRAFT.
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?
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.
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!
We're a place where coders share, stay up-to-date and grow their careers.
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.
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.
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.
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.
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.
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.
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?
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.
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?
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.
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
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.
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?
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.
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.
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!