liveBook · Manning

Integration test

As explained in The Art of Unit Testing 3e

Testing that verifies behavior across multiple integrated components or against external systems such as databases and networks.

A test can pass with fake data and still miss a problem with a real database, file, or network. An integration test checks behavior while leaving some dependencies real. It can look like a unit test: call a production function and check its result. The distinction is that a unit test keeps its dependencies in memory and controls their behavior, while an integration test may rely on systems or conditions outside the test’s control. section 1.11 section 10.1.3

A test enters integration-testing territory when it depends on things such as:

  • A real database, filesystem, REST API, or network. section 1.8
  • The real system clock, if changing time can change the result. section 1.8
  • A database, network, or deployment being available for the test to run. section 1.7.2

Checking a website

A network-dependent test might await `isWebsiteAliveWithAsyncAwait()` and assert that the result has `success === true` and `status === "ok"`. Using `async` and `await` makes the assertions easier to read than a callback with `done()`. It does not turn the test into a unit test: the network call remains real. section 6.1.1 section 6.1.3

Figure 1.7 You can have many failure points in an integration test. All the units have to work together, and each could malfunction, making it harder to find the source of a bug.
01-07

The figure shows why a failed integration test can take longer to debug: any of several cooperating units could be responsible. section 1.8

That broader check is useful, but it costs something. Real dependencies can make tests slower, less predictable, and harder to set up. A failed website check, for example, could reflect application code, network conditions, a firewall, or the external website. Negative cases such as a network outage are also harder to simulate. Passing integration tests add confidence that code works with dependencies it does not control; they do not identify every fault precisely. section 6.1.4 section 10.1.3

Keep fast, dependable unit tests separate from integration tests so a flaky external check does not make every failure easy to dismiss. Run the broader checks as part of an automated testing strategy, alongside lower-level tests rather than instead of them. Before refactoring hard-to-test legacy code, a few integration tests can record existing behavior. After refactoring, replace most of those broad checks with smaller, more maintainable unit tests. section 7.4.3 section 12.3 section 12.4

How The Art of Unit Testing 3e covers it

How deep it goes
Defines the unit-test boundary, works through network-dependent asynchronous tests, and weighs practical failure modes and testing strategy.
Examples
Uses a website availability check, real databases and filesystems, and XML configuration save-and-load tests.
What it assumes
Assumes ES6 JavaScript or TypeScript and npm familiarity while introducing the distinction between unit and integration tests.
What you can do after
Practice/perform integration checks with real dependencies, separate them from fast unit tests, and use a few as safeguards during refactoring.
How it connects
Connects unit tests, asynchronous testing, flaky tests, legacy-code refactoring, and end-to-end testing through choices about dependencies and confidence.

Also explained in

Compare how 40 books explain integration test →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Art of Unit Testing 3e. The section links point to the parts of the book it draws on.