liveBook · Manning

Testing pyramid

As explained in gRPC Microservices in Go

The testing pyramid is a test-distribution model that places isolated unit tests below integration tests and end-to-end tests, with progressively fewer tests and greater execution cost at higher levels.

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

Figure 7.1 Testing pyramid

Use the pyramid diagram to compare test categories, their relative percentages, isolation levels, and execution costs. section 7.1

How gRPC Microservices in Go covers it

How deep it goes
Defines three test levels and explains their isolation, dependencies, execution speed, and cost, but does not prescribe exact percentages.
Examples
Uses an Order service, mocked dependencies, a real database, test containers, and complete application flows as testing examples.
What it assumes
Assumes familiarity with software components and dependencies while defining unit, integration, and end-to-end testing contexts.
What you can do after
Apply it to arrange unit, integration, and end-to-end suites for faster feedback while preserving cross-component verification.
How it connects
Connects unit testing, integration testing, end-to-end testing, test containers, test coverage, and CI pipelines.

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 gRPC Microservices in Go. The section links point to the parts of the book it draws on.