Bookmarks

Integration test

A check of how components or systems interact with one another through their interfaces, with a database and with external services, rather than in isolation.

Also: integration testing

checked 9 Nov

All terms

A unit test checks a function in isolation and an end-to-end test checks the whole system; an integration test sits in the middle and looks at how parts behave at the seams. The seams are where things most often break that unit tests with doubles cannot see: a mismatch in data format, an error in an SQL query, a wrong response code from a neighbouring service.

Two levels in ISTQB CTFL

LevelWhat is checked
Component integrationinterfaces and interaction between components of one application: the data layer with the database, calls between modules and services (CTFL: component integration testing)
System integrationinterfaces between your system and other systems and external services; needs environments close to production (CTFL: system integration testing)

Component integration depends on the build strategy: bottom-up (first check combinations of small modules, replacing missing calling parts with drivers), top-down (missing dependencies are replaced with stubs) or big-bang, where everything is connected at once and checked as a whole.

How such a test works

In practice, an integration test starts a real dependency (a database, a message broker, a neighbouring service) and checks the interaction through the real interface rather than a direct function call. In an article on martinfowler.com, Ham Vocke recommends narrow integration tests: one integration point at a time, with other services replaced by doubles. They are worth writing around every place where the code serialises or parses data, such as REST API calls, reading and writing queues, and file system access.

python
# pytest: test the data layer against a real database (started in a container in CI)def test_create_order_writes_row(db_session):    order = orders.create(user_id=42, total=1500)    row = db_session.query(Order).get(order.id)    assert row.status == "new" and row.total == 1500

How many to keep

In the testing pyramid, integration tests are the middle layer: fewer than unit tests but more than end-to-end ones. In CI, component integration tests run automatically on every build, while system integration gets a separate environment that approximates production.

Sources

the term is written from these pages

Verified 9 Nov

Not to be confused with

what it is mixed up with and how it differs

  • unit test

    A unit test checks a function or class in isolation, with dependencies replaced; an integration test checks how they work together with real dependencies.

  • E2Eend-to-end test

    An end-to-end test follows the user’s whole path through the assembled system; an integration test checks individual seams between components.

In depth in the references

where the topic is covered in detail