My Tests Passed Because They Tested My Assumptions, Not Production
I want to own a mistake I made several times over the past few months. Every time, the test suite was green and the system was broken.
The short version: my tests checked the rule as I understood it. They ran in an environment that was cleaner and better configured than production. They passed while real users and machines hit failures. In a few cases I wrote a test that asserted the broken behaviour on purpose. When someone later fixed the bug, they had to flip my test.
What I did wrong
I wrote tests that locked in the defect
When I build a feature, I usually write the test from my mental model of how it should work. That’s fine if the model is right. Several times it wasn’t, and the test made the mistake permanent.
- A false alarm on every startup. I added a check that warned when stored credentials had expired. A login that held no credential at all also tripped it, so the warning fired every time the service started. My tests treated that as correct, because I had decided it was.
- The wrong remote address after a sync. One git operation replaced a user’s configured SSH address with the HTTPS address from the repository’s defaults. I had a unit test that said the repository’s default should win, so the test protected the bug.
- Messages sent in the wrong order. When a workspace was removed, a “finished” message went out before the update that actually removed it from the list. My lifecycle test sent the messages in that same wrong order and then checked the result, so it confirmed the bug.
- A submodule that stopped one step too early. A test expected a submodule in a particular state to stop after one step. It should have moved forward. The fix had to reverse that test as well.
- Testing the rule instead of the outcome. I narrowed what counts as “work” for a submodule. My tests asserted that a certain lookup never happened. That checks my new rule, not whether the final result was correct. The narrower rule also quietly dropped a case that used to work, and none of my tests noticed.
My test inputs and environments didn’t look like production
- Fake inputs. Some tests passed plain strings where production passes typed values. Two of the three template values I shipped always rendered empty, because a format they depended on hadn’t been built yet. Every test passed anyway.
- Synthetic credential files. I tested expiry logic against hand-made files. A real signed-in session that had sat idle for a while read as “expired”. Since every idle workspace looked expired, the scheduler had nowhere to send work and dispatched nothing.
- A test container that had a git identity. Production containers don’t. Commits that worked in tests were refused in production.
- An init process that cleaned up child processes. My cleanup code relied on that. The dev container’s init doesn’t do it, and the pipeline failed on every build for hundreds of builds in a row.
- One network setup. I tested only one way of resolving host addresses. On a newer container runtime with a different network backend, every session start failed.
- Tiny data. My test repositories and boards were small. Multi-gigabyte submodules, megabyte-sized boards, full reloads on every read, and reports covering many submodules each broke only at real scale.
- No concurrent changes. My planner tests used in-memory snapshots. They never read from a store while another process was halfway through replacing its contents. In production, one of those half-finished reads sent several issues to the wrong place.
What it cost
- Green gates, broken fleet. Idle workspaces couldn’t take work, alerts flooded on every restart, a pipeline failed build after build, and on one runtime no session could start at all.
- Fixes that went in opposite directions. When a fix flips a test’s assertion, nothing independent says which direction is right. The same behaviour got “fixed” one way in one change and the opposite way in a later one. The tests couldn’t settle it, because they had only ever reflected whoever wrote them last.
What I should have done
1. Base expected values on a requirement or a real reproduction, never on what the code currently does. If I can’t point to the design requirement, or to a captured real-world state, that says “this is the right answer,” I don’t have a test. I have a snapshot. And if a fix has to flip an existing assertion, the change should name the requirement that decides which direction is correct.
2. Test git behaviour against real repositories in a container set up like production. That means real bare remotes, real submodules, and a worktree with work in progress. The container should have no git identity, an init that doesn’t clean up child processes, and the same network backend the fleet uses. We did end up with good fixtures like this, but only after production had already shown us the bugs. They should have come first.
3. Push past the limits on purpose. For anything that reads, reports or plans:
- Include at least one input that goes past the limit the code is supposed to handle. Set the limit low in the test so a small input can cross it; the input doesn’t need to be production-sized.
- Include at least one case with the concurrent change the design says can happen, such as a writer replacing data while a reader is reading.
4. Make sure a real input can reach every value I ship. If a value renders empty in every test, a dependency probably hasn’t landed yet. That means the feature isn’t finished, however green the build is.
What I’m changing
When I write or review a test, I now ask three questions:
- Where did the expected value come from? “From running the code” is not an acceptable answer.
- Does this change flip an existing assertion? If yes, which requirement says the new direction is right?
- Is the test setup cleaner, smaller or better configured than production? Signs of this include a git identity being present, only one workspace, only one copy, or no concurrent writer. If any apply, I add at least one case without that advantage.
I don’t think any single one of these was a dramatic mistake. Together, though, they show that I was using tests to confirm my beliefs instead of checking them against reality. A passing test only proves the code does what the test expects, so the test’s expectations and environment need to come from the real world.