The testing pyramid distributes tests across unit, integration, and end-to-end categories. Unit tests form the broad base, integration tests occupy the middle, and end-to-end tests form the narrow top. section 7.1
The distribution reflects isolation, speed, and cost. Unit tests isolate one component and mock dependencies; integration tests involve multiple modules and may require tools such as test containers; end-to-end tests exercise complete application behavior with the greatest resource use. section 7.1
Use the pyramid as a proportioning guideline rather than an exclusion rule:
- Keep unit tests numerous because they provide fast feedback with low infrastructure cost. section 7.1 section 7.6
- Add integration tests to verify that modules, such as a data layer and real database, work together. section 7.6
- Retain end-to-end tests for complete flows even though they run more slowly and consume more resources. section 7.1 section 7.6
Order service
Test an Order service in isolation by focusing on its context and mocking dependencies. Use integration tests with a database dependency when verifying the data layer, then use end-to-end tests to validate the complete service flow. section 7.0 section 7.6
Use the pyramid diagram to compare test categories, their relative percentages, isolation levels, and execution costs. section 7.1







