Test isolation is the quality of executing a test independently, so other tests or external influences cannot affect its outcome. Unit tests verify a small piece of code quickly and in an isolated manner; the disputed question is whether isolation applies primarily to the system under test or to the tests themselves. section 2.1 section 5.0
Two influential interpretations make different trade-offs:
- The London style isolates the system under test from its collaborators by replacing dependencies with test doubles, concentrating each test on one class. section 2.1
- The classical style isolates tests from one another so they can run in parallel, retaining private dependencies and replacing only dependencies shared between tests. section 5.0
- Mocks can support isolation but often create fragile tests that resist refactoring; use them where their benefits outweigh that maintenance cost. section 5.0
Inventory purchase
A classical test constructs a store, adds ten shampoos, and verifies that purchasing five succeeds while inventory falls to five. A London-style test replaces the store with a mock, stubs the inventory check, and verifies that inventory removal occurs once.


