Raimund Krämer

Software Craftsman, Consultant, Coach

Every time I see someone advocating for inverting the test pyramid, or testing everything with slower, more flaky higher level tests, it’s well intended but unfortunately based on wrong assumptions. It’s a perfect example of Brandolini’s Law: People end up with the test ice cream cone all by themselves and are reinforced by advice against a misunderstood version of the test pyramid.

Unit tests that heavily rely on mocking are a design smell because they are coupled to implementation details. If the design is aligned with the domain and tested with sociable unit (or rather behavior) tests, they are less brittle to refactoring, and we can get a very fast test suite to ensure the basic correctness of the code.

Good integration tests test the integrations (!) between modules/services and with 3rd party systems. We need relatively few integration tests to make sure the parts of the system hang together correctly. Relying on a large number of integration and system tests to verify the basic correctness leads to a combinatorial explosion of possible paths through the system that requires more tests to get the same confidence and coverage (mutation coverage, not just line coverage) while running way slower and thus less often.