CHAPTER 1 / 8
Boundaries of type, unit, integration, and E2E tests
Testing layers are not a hierarchy; they are defenses that catch different failures where detection is less costly.
Why this concept became necessary
A type check verifies value shapes, unit tests verify small computations, integration tests verify module, database, and API contracts, and E2E tests verify the flows users see in a real browser. Even if the lower layers pass, serialization and deployment settings at the upper boundaries can still be wrong.
Writing every case as an E2E test is slow and makes causes hard to isolate, while relying only on mocked unit tests misses real integration errors. Place fast tests at the lowest layer where a defect first appears, and cover core journeys through real boundaries.
Testing layers are not a hierarchy; they are defenses that catch different failures where detection is less costly.
Layers fast feedback at small scope with real integration evidence at broad scope.
For each recent defect, classify which gate should have caught it first and find the missing boundaries.
Follow it through a concrete system
Unit tests can quickly check boundary values in a tax-calculation function, but incorrectly serialized monetary units in JSON or a migration missing a column emerge at integration boundaries. Browser E2E checks the full path from the user clicking a button to seeing the final result, but narrowing the cause of failure is costly. Instead of duplicating the same defect checks across all layers, distinguish the least costly detection layer from the critical journeys that must be protected.
When designing testing layers, examine where recent incidents escaped detection rather than asking what percentage should be unit tests. If types were correct but authorization was missing, contract and abuse tests are needed. If the API was correct but submission through the keyboard failed, browser tests are needed. Update the defect classification regularly so the suite follows actual risk.
Selection criteria and failure boundaries
Duplicate fixtures, slow suites, and drift across environments must be managed.
Misconceptions to avoid: It is incorrect to assume that the test pyramid means a fixed ratio or a ban on E2E tests.
Verify it yourself
For each recent defect, classify which gate should have caught it first and find the missing boundaries.
Official sources for this chapter
The technical facts in the text were reviewed against the following primary sources. The author reconstructed the diagrams and comparisons using these materials.
- Microsoft, 「Playwright Best Practices」Review date 2026-08-28 · Scope Latest official documentation