Learn · Strategy

Impact of AI on Testing Shapes

AI makes tests cheap to write. It does not make them cheap to own. That changes which testing shape pays off, which layers grow, and which patterns keep a suite trustworthy when an agent writes half of it.

01 · Economics

What AI changes

Every testing shape is an argument about cost and confidence. AI moves the costs, so the argument has to be re-run.

✍️
writing cost ↓↓

Writing tests is nearly free

Assistants generate unit tests and UI flows in seconds. Volume stops being the constraint.

🔧
ownership cost ↑

Owning them is not

Generated tests often mirror the current implementation. When the code changes, they break or get regenerated, and every one still has to be reviewed and run.

🎯
oracle risk ↑

Tests can bless bugs

An AI that reads the code writes assertions for what the code does, not what it should do. A green suite can encode the bug.

🎲
new layer

Some systems stop being deterministic

When the product calls an LLM, exact-match assertions fail at every level. You need evaluations, not just tests.

02 · Shapes

The shapes, revisited

Bar width is the share of tests at that layer. The badge is the verdict when AI is writing or running a large part of the suite. Each classic shape links to its animated walkthrough.

03 · Decision

Which shape when

Pick by what your system is and how AI touches it, not by what is fashionable.

SituationShapeWhy
Deterministic back-end code, AI assistant writes unit testsPyramidAI is strongest at unit tests along key execution paths. Keep the base wide, but gate generated tests with review and mutation testing so volume does not hide weak assertions.
UI-heavy web app, agents generate component and flow testsTrophyBehaviour-level integration tests survive the frequent refactors agents make. Static checks (types, lint) catch much of what generated code gets wrong, for free.
Services where agents refactor internals oftenDiamondHoneycombTests at the service boundary stay valid while the implementation churns. Implementation-detail unit tests generated against today's code become tomorrow's noise.
Product with LLM-powered featuresPyramid + eval layerTest the deterministic plumbing (prompt building, parsing, tool routing) with ordinary unit and contract tests; judge model behaviour with versioned eval sets and score thresholds; watch it in production.
Agentic system (tools, multi-step plans)Boundary-heavy + evalsMost failures happen at tool-call boundaries. Contract-test each tool, evaluate whole trajectories against scenarios, and keep a few end-to-end runs on real tools.
Untested legacy code, AI used to bootstrap coverageCone → PyramidAI-generated characterization and UI tests are a fine temporary safety net. Plan to push each check down a level as the code becomes testable, or the cone becomes permanent.
04 · Patterns

Patterns that work with AI

The goal is the same as always: fast, trustworthy signal. These patterns keep AI-written and AI-tested code honest.

Review gate for generated tests

Generated tests go through the same pull-request review as production code, with a human owner.

Why: a test nobody understands cannot be trusted when it fails, or when it passes.

Mutation testing as the quality bar

Measure generated tests by how many injected bugs they kill, not by coverage.

Why: coverage counts executed lines; mutation score shows whether assertions actually check anything.

mutmut run --paths-to-mutate src/pricing
# keep generated tests only if mutation score ≥ 80%

Specify first, then generate

Write the expected behaviour (acceptance criteria, Given/When/Then, examples) yourself; let AI turn it into code.

Why: the oracle comes from the requirement, not from the code under test, so the test can catch the bug.

Stable abstractions for agents

Give agents a vocabulary: Page Objects, Screenplay tasks, API clients, fixtures.

Why: generated tests that call login_page.login() survive UI changes; tests full of raw locators do not.

Property and invariant assertions

Assert properties that must always hold: valid JSON, schema, length limits, no PII, totals add up.

Why: they work for non-deterministic output and for inputs nobody thought of. See property-based testing.

Golden datasets and evals

A versioned set of real inputs with expected qualities, scored on every model or prompt change, with pass thresholds.

Why: it is the regression suite for model behaviour; exact-match tests cannot do this job.

evals/support_bot.jsonl   # 300 cases, versioned
assert score("faithfulness") >= 0.92
assert score("refusal_when_unsure") >= 0.95

LLM-as-judge, calibrated

Use a model to grade open-ended output against a rubric, and spot-check its grades against human labels.

Why: it scales evaluation, but an uncalibrated judge just adds another non-deterministic opinion.

Record and replay model calls

Record real LLM responses once and replay them in CI (VCR-style cassettes); refresh them on purpose.

Why: plumbing tests stay fast, free and deterministic, while evals cover live model behaviour separately.

Contract tests at tool boundaries

For each tool an agent can call, test the schema and behaviour of the call itself, like a consumer-driven contract.

Why: agents fail most often at boundaries: wrong arguments, unexpected responses, partial failures.

Tiered execution

A small, critical smoke suite on every pull request; the full suite and evals nightly or before release.

Why: AI-grown suites get big quickly. Tiering keeps pull-request feedback in minutes.

05 · Watch out

Anti-patterns

Most of these are old mistakes that AI makes cheaper to repeat.

The AI ice-cream cone

Agents that turn plain-English steps into browser tests make the UI layer grow fastest. Fix: generate at the lowest layer that can catch the bug.

Coverage as the target

AI can hit 90% coverage with tests that assert almost nothing. Fix: track mutation score and escaped bugs instead.

Tests that mirror the implementation

Generated from the code, they restate it line by line and break on every refactor. Fix: test behaviour at a boundary.

Exact-match on LLM output

Asserting the model's exact wording fails randomly and teaches the team to ignore red builds. Fix: properties, rubrics, evals.

Mocking the model and calling it tested

A mocked LLM proves the plumbing works, not that the feature works. Fix: keep both plumbing tests and evals.

Self-healing that hides bugs

Auto-repaired locators keep tests green while the UI quietly breaks for users. Fix: log and review every heal; fail on large changes.

Takeaway
  1. The classic shapes still hold for deterministic code; AI mostly makes the lower layers cheaper to fill, not less important.
  2. Because writing is cheap and owning is not, prefer layers whose tests survive change: behaviour and boundary tests (Trophy, Diamond).
  3. If your product calls a model, add an evaluation layer; it is a new layer, not a replacement for tests.
  4. Judge AI-written tests by what they catch (mutation score, escaped bugs), never by how many there are.
Sources

Further reading