Automated Testing in CI/CD: Which Test Pyramid Actually Works
The classic test pyramid is a good starting point — but in practice, CI/CD pipelines need a tailored approach. Our experience.
Rethinking the Test Pyramid
The classic pyramid says: many unit tests, few integration tests, barely any E2E tests. In practice with modern web applications, this does not always hold true.
Unit Tests: Fast but Limited
Unit tests are ideal for isolated business logic, calculations, and data validation. But they say nothing about whether your components work together.
Feature Tests: The Sweet Spot
In Laravel projects, feature tests (HTTP tests) are often the best compromise. They test the entire request lifecycle — from the route through the controller and middleware to the database — and still run in milliseconds.
- Database Tests: Use
LazilyRefreshDatabasefor fast, isolated tests with a real database. - Factory States: Define meaningful factory states for different scenarios.
- Assertions: Laravel offers powerful test assertions such as
assertDatabaseHas(),assertRedirect(), andassertSee().
E2E Tests: Use Selectively
Browser tests with tools like Playwright or Dusk should be limited to critical user journeys: login, checkout, registration. They are slow and fragile — but indispensable for happy paths.
Pipeline Integration
In our CI/CD pipelines, unit and feature tests run in parallel, followed by E2E tests only on the staging branch. This keeps feedback cycles short without sacrificing safety.
Questions About This Topic?
We are happy to advise you on the technologies and solutions described in this article.
Get in Touch