The Test Pyramid Is a Lie (and What I Do Instead)

This title could be clearer and more informative.Try out Clickbait Shieldfor free (5 uses left this month).

The classic test pyramid — lots of unit tests, few integration tests — was practical advice for 2009 when spinning up real databases was slow and expensive. With Testcontainers and .NET Aspire, that constraint is gone. The author argues that most real bugs live at the seams (handlers, repositories, HTTP endpoints), where unit tests with mocks fail to catch them. The proposed alternative is a 'testing trophy' shape: a thin base of unit tests for pure domain logic (~15-25%), a thick middle of integration tests against real PostgreSQL/RabbitMQ/Redis (~60-70%), a small cap of E2E tests for critical flows (<10%), and architecture/contract tests as a foundation layer. A concrete example shows how a missing SaveChangesAsync call — undetected by 94% unit test coverage — would have been caught immediately by a single integration test.

6m read timeFrom milanjovanovic.tech
Post cover image
Table of contents
Where the Pyramid Comes FromThe Bug That Convinced MeWhat Unit Tests Are Actually Good AtWhat I Actually Write InsteadThe Usual ObjectionsSummary

Sort: