Why Blackbox Testing Always Wins

Stop testing how the code works. Start testing what the system does, and let AI write the journeys.

Ever since LLMs arrived, there's one thing they've always been terrifyingly good at:

Writing tests.

Not the crap unit tests that mock everything, test nothing real and burn CI minutes on every push. I'm talking about blackbox tests. Tests that don't care how the system is implemented. Tests that care what the system does.

Input goes in. Output comes out. Does it match? That's it.

No mocking of your own services. No internal wiring. No "this test broke because someone renamed a private method."

This post is my case for why that kind of test wins, how I get AI agents to write hundreds of them, and the honest small print that makes the difference between a suite you trust and a suite everyone learns to ignore.

Two rows of the same journey, log in, get token, call /me, right user back, both passing. Under the first, hidden from the test, one Django app and Postgres. Under the second, an auth service, a token service, a profile API and a new database. The test only touches the journey, so it survives.
Same journey, new insides. The test only sees what a user sees, so it survives the rewrite underneath.

What I mean by blackbox

A blackbox test talks to the system the way a user or a client does: through its public API, its UI or its device protocol. It knows the contract. It doesn't know the code.

That's a slightly different thing from "end-to-end". An end-to-end test is about scope, the whole chain from the front door to the database and back. Blackbox is about knowledge, what the test is allowed to know. Most of my tests are both: they drive a whole journey, and they only use what's visible from outside. But you can have a blackbox test of a single service, and you can have a so-called end-to-end test that peeks into tables and mocks half the world. The second one is not what I'm talking about.

The thing a blackbox test protects is a behavioural contract: given this user, in this state, doing this, the system responds with that. Those contracts are what your customers actually depend on. Nobody has ever filed a support ticket about a private method.

Four journeys, four tests

Here's what I do. I point an AI agent at a real user journey and say: write a test for this. End to end. Realistic data. Realistic environment. Test the outcome, not the implementation.

Some examples of the kind of journeys I mean:

→ A user authenticates. Gets a token. The token works on the next call. That's a test.

→ A user enters credentials. The 2FA screen is shown. A code is entered. The welcome screen appears. That's a test.

→ A customer buys an episode. An entitlement is created. The episode plays. The purchase appears in billing. That's a test.

→ An admin changes a plan. The change propagates to the device. The device sees the new channels. That's a test.

Not one assertion. An entire journey, step by step, the way a real human uses the system.

The purchase one is my favourite, because it crosses every layer that tends to break quietly.

Four hops in a row: buy episode at the store API, entitlement in the rights service, playback through the player and CDN, billing in the ledger. Under each, the assertions: order id and price, entitlement for the right user and episode, a working stream, one charge of the correct amount.
One purchase crosses four layers. A journey test asserts at every hop, not just the first status code.

A unit test might tell you that the purchase handler returns 201. Lovely. It won't tell you that the entitlement never got written because an event was dropped, or that the stream URL comes back 403 for this region, or that billing charged twice because a retry wasn't idempotent. Each of those has its own unit tests, and each of those unit tests passes. The customer still can't watch their episode.

Assertions are the whole game

Here's where a lot of "end-to-end" suites go wrong: they drive the whole journey and then assert almost nothing. assert response.status_code == 200 is not a test of a product. It's a test that the server didn't crash.

A good blackbox assertion is about an outcome a person would notice:

→ The token works on the next call, for this user, and not for another one.

→ The welcome screen shows this user's name.

→ Billing has exactly one charge, for the right amount, in the right currency.

→ After cancelling, the device stops seeing the channel.

The negative ones matter as much as the positive ones. A plan downgrade that adds the new channels but forgets to remove the old ones passes a lazy test and fails a real one.

My unit-test-versus-blackbox line is this: a unit test says "the add_to_cart function returns 200". A blackbox test says "a customer in Melbourne with a prepaid card can buy a subscription, see it on their device, get charged correctly, and cancel without calling support."

Which one do you trust more?

Here's roughly what one looks like

This is an illustrative example, not code from any real system, but it shows the shape. It's plain Python and pytest, talking to a staging API over HTTP. Nothing is imported from the application.

import uuid
from tests.journeys.client import Api, poll_until  # thin HTTP helpers, no app imports


def test_customer_buys_episode_and_can_watch_it(api: Api, sandbox_card):
    # realistic, unique, disposable customer for this run only
    email = f"journey+{uuid.uuid4().hex[:8]}@example.test"
    customer = api.signup(email=email, city="Melbourne", card=sandbox_card("prepaid"))

    order = customer.buy(episode_id="S01E03")
    assert order.status == "paid"
    assert order.amount == customer.price_of("S01E03")

    # entitlement is written asynchronously: wait for it, with a hard limit
    poll_until(lambda: customer.can_play("S01E03"), timeout_s=30)

    stream = customer.play("S01E03")
    assert stream.http_status == 200
    assert stream.manifest_has_segments()

    charges = customer.billing_history()
    assert [c.reference for c in charges] == [order.id]  # exactly one charge

Read it top to bottom and you know what the product promises. That's not an accident. I'll come back to it.

Determinism is designed, not hoped for

The biggest reason people distrust journey tests is that they've seen bad ones. Tests that pass on Tuesday and fail on Wednesday. Tests that only work if run in a particular order. The fix isn't to write fewer of them. It's to build them properly.

Fixtures. Every test creates its own data: its own user, its own account, its own order. Synthetic but realistic: real-looking names, real postcodes, real plan combinations, card types that exist. Never real customer data. A test that depends on "the demo user" will eventually fight another test over it.

Setup and teardown. Whatever a test creates, it cleans up, or it creates it in a namespace that gets thrown away. Leftover data from the last run is one of the most common sources of mysterious failures.

Payments. Always sandbox. Test cards, a payment provider's test mode, a ledger that can't move real money. Nobody should get a real charge because a test ran.

Waiting. Modern systems are eventually consistent. Entitlements are written by a consumer, plans propagate through a cache, a device picks up changes on its next sync. The wrong answer is sleep(5). That's too slow when the system is fast and too short when it's slow. The right answer is to poll for the outcome with a bounded timeout, like poll_until above, and fail with a clear message if the deadline passes. "Eventually" must still have a deadline, otherwise you're not testing a promise.

The three objections

There are three objections I hear every time.

"It's slow."

Run them in parallel. Massively parallel. If the journeys are independent, every worker gets its own users and its own data, and a few hundred tests across tens of workers finish in minutes rather than hours.

The honest small print is that parallelism has a ceiling, and it's usually not the number of workers.

A suite queue fans out to many workers, each with its own user, data and namespace. All of them funnel back into shared dependencies: a shared test database, an auth rate limit, a payment sandbox and one slow service, which set the real clock.
Workers scale out. Shared dependencies don't. Your suite time is the slowest journey plus whatever everyone queues on.

Fifty workers all logging in at once will find your auth rate limit. They'll find the one small staging database, the payment sandbox's request limit, the service everyone calls that only has one replica. Suite time ends up being roughly the slowest journey plus the queueing at whatever is shared. So the work is: make tests independent, give the environment enough capacity, and treat a sudden slowdown as information about your system, not just a CI annoyance.

"It's flaky."

A flaky test is a signal, not a nuisance. Often it's telling you the product isn't behaving deterministically: a race between two writes, a retry that double-charges, an event lost under load, a cache serving a stale plan. Those are product bugs, and some of them are exactly the bugs your customers hit once in a hundred times and you can never reproduce. Fix the product.

But I want to be precise here, because "every flaky test is a product bug" isn't true, and believing it wastes days.

A flaky test forks two ways. The product: a race between writes, a retry that double-charges, a lost event, a stale cache, so fix the product. The harness or environment: sleeps instead of polling, shared users, leftover data, a staging dependency down, so fix the test or environment.
A flaky test is always a signal. Find out which branch it's on before you blame the product or the test.

Flakiness can also come from the test harness (a sleep instead of polling, two tests sharing a user, an order dependency) or from the environment (a staging dependency that's down, a noisy neighbour, a clock that's off). The discipline is to find out which branch you're on. Rerun with request ids, timings and logs. If it's the product, fix the product. If it's the test or the environment, fix that, properly, not by adding a retry that hides both.

What makes outcome-based tests stable is that they aren't coupled to incidental details. If the login journey returns a valid token, it doesn't matter which microservice generated it or which database it hit. The outcome stays the same when the internals change.

"It's hard to write."

It was. Before LLMs.

Where the AI comes in

Now you describe the journey in plain English and the agent writes the test. With realistic data. With proper assertions. With setup and teardown. You review it, tune it and add it to the suite.

The review is not optional, and it's where my time actually goes.

A loop: journey in plain English, agent drafts the test, human review, run against a real environment, evidence with ids, logs and diffs, then back to the journey. In the middle the review asks: does it assert the outcome, or just echo the code, and would it fail if the product were broken?
The AI writes it. You decide if it's true. Review asks one question: would this fail if the product were broken?

The main failure mode of an AI-written test is that it parrots the implementation. If you let the agent read the code first, it will happily write a test that asserts whatever the code currently does, bugs included. So I give it the journey and the public contract, not the internals. Then I review with a few questions:

→ Does it assert the outcome a user would notice, or just a status code?

→ Would it fail if the product were broken? (The quickest check: break it on purpose, and watch the test go red.)

→ Is the data realistic, unique and cleaned up?

→ Does it wait for outcomes with a deadline, or with sleeps?

Then it runs against a real environment, and the evidence comes back: pass or fail, with ids, logs and diffs I can actually act on. That loop is fast enough that the bottleneck stops being typing tests and becomes knowing which journeys matter.

For me, that went from "we should write more integration tests" to "we have about a thousand blackbox tests" in months. Not years. That's my own experience on my own projects, not a benchmark, and your mileage will depend on how testable your environment is. But the shift in what's practical is real.

The suite is the spec

Here's the part that will really cook your brain: these tests double as documentation.

A short illustrative test: a prepaid customer in Melbourne subscribes to Sports, the device sees it, billing shows one charge, they cancel, the device no longer sees it, no support tickets. Arrows: a new developer reads what the product does, and CI checks it is still true every deploy.
A suite that reads like a spec, and proves itself on every deploy.

Read a blackbox test and you know exactly what the system does. Not what the code says. What the system actually does when a real user touches it.

New developer joins the team? Don't just give them a wiki. Give them the test suite. Every user journey, spelled out, with realistic data, verified against a real environment. Unlike the wiki, it can't silently go out of date, because the day it stops being true, CI goes red.

That's not a test suite. That's a living specification.

What happens when you refactor

Internal refactors stop breaking tests.

Because the tests don't know about the internals, they don't care that you rewrote the payment module from scratch. They care that the customer can still buy things and get charged correctly. Rewrite modules, swap databases, split a monolith into services: if the outcomes still match, you're good.

The one caveat worth saying out loud: if a refactor changes something users can see, a response field, an error message, a timing a device depends on, the blackbox suite will break. That's not a weakness. That's the suite doing its job, telling you that your "internal" change wasn't internal.

Try getting that signal from 3,000 unit tests coupled to internal method signatures. I'll wait.

Where unit tests still belong

I'm deliberately provocative about unit tests, so let me be fair to them. A pure function that calculates GST, parses a date format or rounds a currency amount has dozens of edge cases, and a unit test is the fastest, cheapest place to pin them down. I still write those.

What I don't write any more is the mock-everything kind: tests that stub out the database, the queue and three of my own services, then assert that a function called another function. Those tests break on every refactor and pass through every real outage. They measure the wrong thing.

The balance I've landed on: unit tests for logic with many edge cases, blackbox tests for every journey a user or client depends on. When I have to choose where to spend effort, the journeys win.

Start today

Every blackbox test you don't write is a user journey you're not protecting.

Every journey you're not protecting is a production incident waiting to happen.

Every production incident is a week of your life you're not getting back.

If you're relying on unit tests and manual QA alone to tell you the product works, you're flying with instruments that measure the wrong thing.

Stop testing how the code works. Start testing what the system does.

Pick your five most important user journeys. Describe each one in plain English. Hand them to an agent, review what it writes against the questions above, and run them on every deploy. Not next sprint. Not next quarter. Today.

The AI will write the tests. You just need to describe the journeys.

What's stopping you?

All drawings and code here are illustrative, not taken from any production system.

edit

Newsletter

Get new writing by email

Occasional notes on Python, Django, AWS and building software. No spam, unsubscribe anytime. Prefer a feed reader? RSS.