Test above the seam
We shipped two bugs in two days, and every test passed both times. The pieces were right. The handoff between them was not. This is the rule we wrote afterwards, and the mistake we kept making while writing it.
Two bugs, one shape
The first: a request meant for one handler was quietly answered by another route registered ahead of it. The handler's own tests all passed, because they called the handler directly. They started below the point where the request went astray.
The second: a field sent over the wire was dropped by the HTTP layer before it reached storage. Every storage test passed, because they wrote to the store directly. They never crossed the wire.
Both times the components worked. Both times the system didn't.
The components worked. The system didn't.
The seam
A seam is any boundary where one part hands state, data or control to another: a route table to a handler, an HTTP body to a store, a model tool call to the door it is meant to open.
Unit tests ask whether a piece works. End-to-end tests ask whether the whole thing works. Almost nothing asks the question in between: did A actually hand the thing to B?
So the rule is simple. Every stateful or security-relevant boundary gets at least one test that starts above it and checks below it. A test that starts below the seam cannot see the seam.
A test that starts below the seam cannot see the seam.
The mistake we kept making
Writing those tests is where it went wrong again, three times in one block.
One called a function that takes no arguments, so a deliberate break that dropped every argument in the handoff left all the checks green. One checked for the word "error" in a message that a correct result also contained. One passed a field under the wrong name, so the call was refused before it ever reached the boundary it claimed to test.
Each test looked like coverage. None of them could fail for the reason it existed.
Each test looked like coverage. None could fail for the reason it existed.
Break the connection, not the units
So a seam test isn't trusted until we've broken the connection on purpose and watched it go red. Not a unit, the connection. If the break also fails the unit tests, it hasn't shown that the seam is covered.
And a new check is only trusted once it has failed on a deliberately broken build and passed on the correct one. A check that has only ever met a broken build cannot tell the two apart. We once had one that asserted a defect as the requirement, and passed because the defect was there.
A test you've never seen fail can't tell broken from working.