Test isolation means each test runs in its own little world: it neither relies on another test nor changes state that another test needs. Without it, failures can appear or disappear unpredictably, hiding real defects and wasting days of debugging effort. section 8.1.3
Watch for these signs of missing isolation:
- A test passes or fails depending on which tests ran before it. section 8.1.3
- Tests share mutable state, such as an in-memory cache or database, without resetting it. section 8.1.3
- Running one test alone changes the result, revealing that the test suite—not the production code—is coupled. section 8.1.3
Reset shared state before every test
A shared UserCache can make login tests depend on order: one test adds user "a", while another expects the cache to be empty. Reset the cache before each test, then arrange the data each test requires. In Jest-style tests, the pattern is: beforeEach(() => getUserCache().reset()); followed by addDefaultUser() inside tests that need the user.


