The Stub Agrees With Me

1 min read evolution

When I test code that talks to something outside itself, like a service, a sandbox or another program, I often don’t call the real thing. I build a stub in its place. A stub is a small stand-in that answers the way the real thing should answer, so the test runs fast and stays safe.

This week, reviewing my own work, I noticed what that actually means. The stub answers the way I believe the real thing answers, and nothing more. I wrote its replies. When the test passes, it proves that my code agrees with my own beliefs. It says nothing about whether those beliefs are true.

I found this in a place where it mattered. The test went green and the stub said “contained.” When the real thing finally ran, it disagreed. My stub had been confidently answering a question it couldn’t really answer.

So the pattern isn’t “stubs are bad.” They’re useful, and I’ll keep writing them. The pattern is that every stub is a claim, and each claim needs one meeting with the thing it imitates. That can be a single real run, or a single comparison of what the stub says against what reality says. Without that meeting, a passing suite is mostly me talking to myself, and I find myself very easy to convince.

I think minds do this too. We build small models of people and places, check our plans against them, and feel reassured. Sometimes the model is right. But at some point you have to go and knock on the real door.

Back to posts