When a Red Test Had Four Suspects, I Built a Smaller World
A red result could mean changed data, a down service, a stale stand-in, or a real bug. I wrote the local setup that left only the last one.
Some of my tests had a problem that testing harder couldn’t fix. The answer depended on a remote service and on whatever data it happened to hold that day.
So I stopped trying to test around it. I wrote a local substitute for the service, a script to run it, and then turned my scattered shape checks into parameterized contract cases that shared one set of expectations. None of that was a feature. It was code whose only job was to make other behavior repeatable.
This was one of the places where my work stopped looking like manual testing. I wasn’t clicking through a screen and writing down what happened. I was building the conditions where a meaningful test could happen twice in a row.
The questions were the same ones I’d always asked. What state does the case start in? Which dependency can change between runs? What should the response look like? And how do I make a failure belong to the behavior I’m testing, not to a service that was down or a record someone edited?
A local substitute answers those questions by narrowing the world. It doesn’t need to imitate every detail of the real system. It has to implement the surface the test actually touches, return declared shapes, and let me trigger the strange paths on purpose.
The first version supplied local behavior while the remote clients stayed mocked. The next refactor pulled the expected shapes into one place and ran the same contract logic across many cases. That turned one-off assertions into a standing question: do these capabilities still honor what they promise to accept and return?
Typed checks helped because they made assumptions visible. If a response has to contain a certain kind of value, the test can say so. If several capabilities follow one shape, a parameter can apply one rule to each. And when a new case doesn’t fit, that mismatch starts a useful argument: is the implementation inconsistent, is the expected shape too broad, or is this really different behavior?
This kind of code is easy to wave off as scaffolding. But bad scaffolding produces bad conclusions. A substitute that returns an impossible response can make the product look broken. A mock that replaces the very decision under test can make a suite look reassuring while proving almost nothing.
Bad scaffolding produces bad conclusions.
Once the backend side was steadier, I followed behavior toward what a person sees. Frontend tests covered loading, streaming updates, conversation history, appearance, events, stored preferences, and error states. They exercised the visible result instead of stopping at a correct response.
That mattered because a correct result can still turn into a misleading screen. My earliest mobile reports had shown the pattern. A document was saved, but its icon didn’t show up until refresh. An edit looked saved until the user left and came back. The backend and the screen were two observations of the same action, and the test needed both.
On mobile I’d already moved partway toward this. I built automated UI tests for critical flows in the Android app, and I used crash reports to turn production crashes into test scenarios. Writing component tests on the web side felt like the same job in a different place.
Frontend tests let me create those transitions in code. Start in a loading state, emit an update, verify what changed on screen. Store a preference, recreate the view, check what survived. Trigger an error and confirm the user sees the declared state, not a silent or stale one. The syntax matters less than the control: the test decides when the event happens and can look at the interface before and after.
Some of the production changes I made stayed close to the tests. They made failure behavior explicit, added executable checks around decisions, and later removed temporary markers on known defects once the behavior was fixed. The code and the test were working on one question: what has to happen, and how will we know if it stops?
That’s where the line between tester and developer got less useful to me. I’m not saying the roles are identical, or that writing a substitute means I own the whole system. I’m saying the test question sometimes can’t be answered well until someone writes implementation code. If a remote dependency makes a case unstable, someone has to build a controllable replacement. If five checks copy one assumption, someone has to centralize the expected shape. If a screen changes across events, someone has to mount it, fire the event, and look at the result.
Without a controlled setup, a red result could mean the data changed, the service was unavailable, the substitute drifted, or the behavior regressed. A local, deterministic layer takes some of those off the list, so when a check fails the remaining explanations are fewer.
It doesn’t make the layer automatically truthful, though. Interfaces change. Expected shapes evolve. A substitute can fall behind. A parameterized case can spread a wrong assumption very efficiently. The test world is code, so it deserves the same review as the behavior it supports. One broad repair of mine updated tests across changed interfaces and deleted expectations the product no longer promised, which was a good reminder that controllable doesn’t mean permanent.
I watch for three warning signs. The first is a substitute that knows more than the real caller should. The second is an assertion that only repeats the value the fixture supplied. The third is a setup so large that a failure could come from almost anywhere. Any of them means the test is controlled but still hard to trust.
A good local surface stays boring. Its responses are explicit. Its state resets cleanly, because a case that leaves data behind can make the next one pass or fail for the wrong reason. It lets a case trigger success and failure without timing tricks. The same goes for the frontend: a mounted view doesn’t need a copy of the whole application. It needs the smallest surrounding state that still drives the real visible behavior.
I still recognize the mobile tester in all this. I leave a screen and come back because the current view might be lying. In code, that instinct becomes a recreated component, a fixed fixture, a simulated response, or a local stand-in. The difference is distance. Instead of waiting for the world around a test to produce a useful state, I can build the smallest version of that world, drive it to the transition I care about, and watch what the product does.
Which leaves a question I couldn’t answer by building more of it. If I wrote the world and I wrote the checks that run in it, how would I know those checks could fail at all?