Unit-Test Isolation
Question
Should you unit test in isolation?
Short interview answer
Usually yes: a unit test should isolate the unit of work from external systems so it is fast, repeatable, and identifies the behavior that failed. Tests that intentionally exercise integrations belong in the integration-test layer.
Detailed answer
Isolation does not mean testing private implementation details or pretending collaborators do not exist. It means controlling dependencies that would make the result variable or slow. For example, inject a clock into expiry logic so the test can use a fixed instant, and replace a network gateway with a test double when the unit’s behavior—not the gateway—is under test. Keep a separate integration test to prove the real gateway configuration works. This division gives meaningful failures: a unit-test failure points to local behavior, while an integration-test failure can reveal an issue at a real boundary.