Skip to main content

Fixtures and Integration Checks

What this concept is​

A fixture is controlled input with a known purpose. A unit-level check isolates a function; an integration check exercises components together. A useful test suite distinguishes both and states what its cases can detect.

Why it matters here​

Internet-dependent tests can fail for reasons unrelated to the code. Controlled local tests make failures easier to diagnose while a real loopback exchange still checks the connection between components.

Concrete example​

Calling interpret(404, "application/json", b'{"sessions":[]}') tests whether the boundary rejects an error status. It does not prove the transport preserves 404. The live test requests /missing and passes the returned status, headers and body to the interpreter. If the adapter incorrectly rewrote errors to 200, the integration could expose that difference.

Similarly, a malformed-body fixture isolates JSON handling; /broken exercises server-to-client delivery of those bytes. Both are useful, but they answer different questions.

Common confusion / misconception​

A test that computes the expected result using the same buggy function is not independent. A passing fixture suite cannot establish resilience to every network failure. More test names do not automatically mean better coverage.

How to use it​

Choose a boundary, a defect it could contain and a case that would distinguish the defect from correct behavior. Keep ordinary, empty, duplicate and invalid cases. Add one test before repairing an observed bug. Preserve the original failing result and explain how the new test catches recurrence.

Check yourself​

Why is an empty fixture alone insufficient to catch deduplication? Removing duplicates changes nothing in an empty input. Use repeated valid values with an independently calculated count.

Mini drill or application​

Propose a realistic faulty implementation and the smallest fixture that catches it. Then add a live endpoint only if you need to verify transport behavior not already covered by an existing route.

Read this only if stuck​

Python urllib.request is the adapter reference; HTTP overview supplies the message model. Our test strategy is an instructional design, not a complete protocol compliance suite.