Test pyramid: shape of test investment by type.
/\ / \ Few end-to-end tests (slow, expensive, brittle) /----\ / \ Some integration tests (moderate speed) /--------\ / \ Many unit tests (fast, cheap, focused) /____________\
Bottom: Unit tests (most).
- Apex unit tests — code-level.
- Jest tests — LWC.
- Fast — milliseconds.
- Reliable — deterministic.
- Cheap — runs on every commit.
Aim: 70-80% of total test count.
Middle: Integration tests.
- Component tests — multi-class flows.
- API tests — Salesforce APIs.
- Mock external calls — controlled environment.
- Moderate speed — seconds.
Aim: 15-20% of test count.
Top: End-to-end tests.
- UI automation — Provar / Selenium / Cypress.
- Full system — frontend + backend + integrations.
- Slow — minutes.
- Brittle — UI changes break.
- Expensive to maintain.
Aim: 5-10% of test count.
Why pyramid shape:
- Cost — top-of-pyramid tests cost more per test (writing, running, maintaining).
- Speed — top tests slower; CI cycles.
- Reliability — top tests more flaky.
Anti-pattern: Inverted pyramid.
- Many UI tests, few unit tests.
- Slow CI, brittle, expensive.
- Common in immature QA practices.
Anti-pattern: Hourglass (no integration tests).
- Unit + UI but no integration.
- Integration bugs missed.
Architectural decisions:
- Code structure matters — more unit-testable if classes have clear boundaries.
- Mocking enables more unit tests.
- Page object models keep UI tests maintainable.
Senior QA insight: test pyramid is cost optimization. Most tests should be cheap and fast.
The senior framing: invest in unit tests; restrain UI tests. That's the pyramid.
