You ask your AI coding agent to implement a FastAPI endpoint, then ask it to write the unit tests. pytest turns green. pytest --cov reports 100% line coverage. The diff looks clean, the assertions are readable, and the PR is ready to merge.

Three days later, a client sends a slightly malformed payload and your endpoint returns a 500 error or silently applies a negative discount.

This is not a freak incident. With AI-written tests generated in the same session as the implementation, both artifacts share the exact same implicit assumptions. The tests do not prove that the code survives reality: they only prove that the code matches what the model had in mind when it wrote it.

This article opens a five-part series on testing techniques that break this confirmation loop: adversarial review with isolated agents, property-based testing, coverage-guided fuzzing, and mutation testing.

Why 100% coverage with AI proves nothing

Code coverage only measures which lines were executed during the test run. It says nothing about the values passed in, nor about the branches that do not exist in the code.

A missing validation check has zero uncovered lines. A forgotten edge case never shows up in a coverage report.

Here is a minimal Python example, typical of what an assistant generates when asked for a shopping cart total with a discount code:

python
from dataclasses import dataclass
from decimal import Decimal


@dataclass(frozen=True)
class CartItem:
    sku: str
    unit_price: Decimal
    quantity: int


def calculate_total(items: list[CartItem], discount_percent: float = 0.0) -> Decimal:
    subtotal = sum((item.unit_price * item.quantity for item in items), Decimal("0"))
    discount = subtotal * Decimal(str(discount_percent)) / Decimal("100")
    return max(Decimal("0"), (subtotal - discount).quantize(Decimal("0.01")))

Right afterward, the agent writes the matching unit tests:

python
from decimal import Decimal
from cart import CartItem, calculate_total


def test_calculate_total_without_discount():
    items = [CartItem(sku="BOOK-1", unit_price=Decimal("20.00"), quantity=2)]
    assert calculate_total(items) == Decimal("40.00")


def test_calculate_total_with_discount():
    items = [CartItem(sku="BOOK-1", unit_price=Decimal("20.00"), quantity=2)]
    assert calculate_total(items, discount_percent=15.0) == Decimal("34.00")


def test_calculate_total_caps_at_zero():
    items = [CartItem(sku="BOOK-1", unit_price=Decimal("10.00"), quantity=1)]
    assert calculate_total(items, discount_percent=150.0) == Decimal("0.00")

Coverage: 100%. Every test is green. Yet three serious bugs are already sitting in those five lines:

  1. Negative quantity: CartItem(sku="BOOK-1", unit_price=Decimal("20.00"), quantity=-3) passes silently and subtracts from the cost of other items in the cart.
  2. Negative discount: discount_percent=-20.0 silently inflates the invoice by 20% instead of raising an error.
  3. Special floating-point values: discount_percent=float("nan") or float("inf") triggers an InvalidOperation inside quantize() and crashes the request.

Why did the AI write zero tests for these three cases? Because it wrote the tests while looking at its own code, under the exact same mental model of a “normal cart”.

Three recurring biases in AI-generated tests

In real Python, Django, and FastAPI codebases, LLM-generated test suites almost always suffer from the same three structural flaws.

Confirmation bias from shared context

When the agent already generated the function in its context window, it knows the happy path it just coded. Its tests mechanically trace the existing branches (if, else, max), not the cases it forgot to handle.

Mirror (tautological) tests

On slightly more involved logic, the model tends to duplicate the implementation formula inside the test to compute the expected value. If the formula has a rounding bug or an off-by-one error, the test happily validates the bug.

Over-mocking that hides real boundaries

When code touches a database, Pydantic serialization, or an external API, the agent often mocks the whole boundary so the test runs fast and passes on the first try. The test ends up proving that the mock returns what it was configured to return, not that the query or validation actually works.

Breaking the confirmation loop

The issue is not using AI to write code. The issue is asking the same actor, inside the same context, to act as both developer and auditor using hand-picked examples.

To eliminate shared blind spots, you need independence in how the code is challenged. Three complementary techniques change your confidence level completely:

TechniqueWhat it changesBugs it catches
Adversarial reviewIsolated agents with zero authoring history try to break the codeValidation gaps, business logic flaws, race conditions, authorization bypasses
Property-based testingYou declare general invariants instead of fixed examplesNumeric edge cases, sorting bugs, idempotency, precision loss, Unicode traps
Coverage-guided fuzzingAn engine floods code or APIs with mutated inputs guided by reached branchesUnhandled 500 errors, parser crashes, algorithmic DoS, OpenAPI schema violations

These three techniques do not replace standard unit tests or TDD and the Red-Green-Refactor cycle. Example-based tests remain essential to document explicit business rules and lock down known regressions. The techniques above cover exactly what hand-picked examples miss.

Depending on your system’s criticality, four additional approaches extend this toolkit further: mutation testing (deliberately mutating your code to check whether your tests fail), differential testing (comparing two implementations on identical inputs), metamorphic testing (checking relationships between outputs when no exact oracle exists), and evals (measuring non-deterministic behavior in LLM-powered features).

What comes next in this series

Each week, one article will walk through one of the four core techniques applied to real Python backend code:

  1. Adversarial review: orchestrating two isolated reviewer agents and a judge agent to audit a FastAPI endpoint before opening a PR.
  2. Property-based testing: moving from examples to invariants with Hypothesis and seeing how shrinking isolates the minimal failing case.
  3. Coverage-guided fuzzing: stressing Python functions with Atheris and OpenAPI endpoints with Schemathesis.
  4. Mutation testing: injecting deliberate faults with mutmut to verify that your tests genuinely fail when the code breaks.

Conclusion

Seeing 100% green coverage on AI-written code creates a dangerous illusion of safety. Coverage never measures what nobody thought to write. Turning a decorative test suite into a real production safety net requires checks that do not share the code’s assumptions: an isolated adversarial perspective, mathematical invariants, and unpredictable inputs.