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
| Level | What is checked |
|---|---|
| Component integration | interfaces and interaction between components of one application: the data layer with the database, calls between modules and services (CTFL: component integration testing) |
| System integration | interfaces 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.
# 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 == 1500How 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 pagesVerified 9 Nov