Skip to content

Integration test

An integration test exercises two or more units together — a service and its database, an API client and the server — to verify that the contract between them holds, without isolating the collaborators.

Definition

What it is

The layer sits between unit tests (isolated, milliseconds) and end-to-end tests (whole system, minutes). Integration tests catch the class of defects that unit tests cannot see by design: mismatched schemas, missing migrations, wire-protocol drift, transaction boundaries, serialisation bugs, connection pool exhaustion, timezone handling. These defects live in the seams between components, and only an integration test crosses the seams.

Why it matters

The economics are clear from the industry data. The Consortium for Information & Software Quality (CISQ) 2022 report estimates the cost of poor software quality in the US alone at $2.41 trillion in 2022, with an estimated $607 billion attributable to legacy systems that lack sufficient integration coverage [1]. Integration failures are a disproportionate share of those costs because they surface in production, not in the developer's IDE.

The scale argument is again GitLab, whose public dataset (February 2025) shows 44,893 integration tests at 15.55% of the suite, and Chrome's CI system, which runs ~50,000 C++ integration tests per change to catch cross-module regressions [2] [3]. The ratio — 70-80% unit, 10-20% integration — is the operational shape of a healthy suite, formalized in the test pyramid (see test-pyramid).

How it works

graph LR
  A[Test] --> B[Service A]
  B --> C[(Real DB<br/>or in-memory)]
  B --> D[Service B<br/>real or wiremock]
  C --> E[Assert on state]
  D --> E
  style B fill:#E8F5E9
  style C fill:#E8F5E9

Three patterns dominate. In-memory substitutes (SQLite, H2, fakeredis) trade fidelity for speed; good for validating query logic, bad for validating migration or vendor-specific behaviour. Wiremock services (WireMock, MSW) stub the HTTP layer; good for testing error paths and timeouts, bad for validating the real API's evolution. Test containers (Testcontainers, 2015) boot the real service in Docker; highest fidelity, highest cost, the modern default for teams that can afford it.

Integration vs unit vs e2e

Aspect

Unit

Integration

End-to-end

Scope

One unit

2-N units

Whole system

Collaborators

All mocked

Real or substitute

Real

Speed

Milliseconds

Hundreds of ms

Minutes

Failure locates

Unit

Contract boundary

User flow

Coverage in healthy suite

70-80%

10-20%

5-10%

Common failures

Origin

Before distributed systems, "integration" was a QA phase that happened after development, not a test category. The 1990s shift to client-server and multi-tier architectures created the need for tests that crossed boundaries; JUnit 1997 and its ports made the practice feasible. Cohn's Succeeding with Agile (2009) formalized the layer in the pyramid. Testcontainers (2015) brought real-dependency testing to CI at scale, and by the 2020s integration tests were the default second layer for any serious team.

  1. 1997 — JUnit; integration testing becomes feasible in CI

  2. 2004 — Spring Framework popularises integration tests against real DB

  3. 2009 — Cohn's test pyramid formalises the layer

  4. 2015 — Testcontainers: real deps in Docker for CI

  5. 2020s — GitLab publishes 44,893 integration tests (15.55%)

An integration test is one that crosses a boundary. If it does not cross a boundary, it is either a unit test that has been mislabelled, or a system test that needs a smaller scope.

— adapted from Martin Fowler, *IntegrationTest*, 2004
15,55% · integration tests en el suite de GitLab (GitLab 2025)
44.893 · integration tests en GitLab CE+EE (GitLab 2025)
~50k · integration tests por cambio en Chromium CI (Chromium 2024)
607 B USD · coste de sistemas legacy sin cobertura adecuada (CISQ 2022)

Evidence

FAQ

What counts as a boundary worth integrating?

Database, queue, HTTP client, file system, external service, in-process framework. If the collaborator talks to something outside the process, it is a boundary.

In-memory or real database?

In-memory for query-logic tests (fast, isolated); real database for migration, transaction and vendor-behaviour tests. Most teams need both.

How many integration tests?

10-20% of the suite. Enough to cover every boundary crossing on the critical path; not so many that CI minutes dominate.

Can I run integration tests in parallel?

Yes, if the databases and queues are isolated per test (container per test, or unique schemas). Shared state is the source of flakiness.

Connections

Etymology

Origin: compound

  • integration (noun): from Latin integrare, "to make whole"
  • test (noun): from Latin testum, "earthen pot"

Semantic network

Integration software-tTest pyramUnit testEnd-to-endTest pyramContract tTest doubl

● broader ● narrower ● related

Sources