liveBook · Manning

Testing pyramid

As explained in Unit Testing Principles, Practices, and Patterns

The Test Pyramid is a testing strategy that recommends a relative distribution of unit, integration, and end-to-end tests, with more tests in lower layers.

The testing pyramid recommends a relative distribution of unit, integration, and end-to-end tests. Unit tests form the majority, integration tests occupy the middle, and end-to-end tests remain the minority. Lower layers favor fast feedback; higher layers favor protection against regressions. The exact ratio depends on project complexity, but every layer should resist refactoring and minimize false positives. section 4.5 section 4.6

Use the pyramid as a cost-and-coverage guideline:

  • Check as many business-scenario edge cases as possible with fast, inexpensive unit tests. section 8.1
  • Use integration tests for one happy path per business scenario and for edge cases that unit tests cannot cover. section 8.1
  • Keep integration tests fewer because out-of-process dependencies make them slower and more expensive to maintain, despite stronger system-level regression protection. section 8.8
  • Adjust the shape for complexity: simple projects may need equal numbers of unit and integration tests, or no unit tests in trivial cases. section 8.8

A business scenario

For a scenario such as changing an email address, test the domain model's edge cases with unit tests, then use an integration test to exercise the controller and the system's successful path. Keep communications with unmanaged dependencies mocked, while using real managed dependencies where required by the integration boundary. section 8.1 section 8.8

Figure 4.12. Different types of tests in the pyramid make different choices between fast feedback and protection against regressions. End-to-end tests favor protection against regressions, unit tests emphasize fast feedback, and integration tests lie in the middle.

Compare how unit, integration, and end-to-end tests trade execution speed against regression protection. section 4.5

How Unit Testing Principles, Practices, and Patterns covers it

How deep it goes
Defines the three-layer ratio and allocation rules, but leaves the exact mix to project complexity.
Examples
Uses pyramid layers, business-scenario edge cases, happy paths, controllers, domain models, databases, and dependency boundaries.
What it assumes
Assumes familiarity with unit tests, integration tests, end-to-end tests, regression protection, refactoring, and feedback speed.
What you can do after
Apply it by shifting edge-case coverage toward unit tests and reserving integration tests for system-level paths and uncovered cases.
How it connects
Connects unit testing, integration testing, end-to-end testing, regression testing, refactoring, and fast feedback.

Also explained in

Compare how 8 books explain testing pyramid →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Unit Testing Principles, Practices, and Patterns. The section links point to the parts of the book it draws on.