13.1.2.2 CI Integration Dependencies
A focused guide to CI Integration Dependencies, connecting core concepts with practical Docker and container operations.
CI integration dependencies are the supporting services — a database, a cache, a message broker — that an integration test suite actually needs running alongside the application, typically provided through Compose within the CI pipeline to closely mirror the application's real dependency relationships.
Defining Integration Dependencies for a CI Run
A Compose file specifically for CI brings up the application alongside its real dependencies, in contrast to unit tests, which avoid needing these dependencies at all.
services:
app:
build:
target: test
db:
image: postgres:16
environment:
- POSTGRES_DB=test_db
docker compose -f docker-compose.test.yml run --rm app npm run test:integration
Why Integration Tests Specifically Need Real Dependencies
Unlike unit tests, which mock external dependencies, integration tests are specifically meant to verify the application's actual interaction with a real database, cache, or other dependency, requiring those dependencies to genuinely be present and running.
docker compose -f docker-compose.test.yml up -d db
docker compose -f docker-compose.test.yml run --rm app npm run test:integration
Ensuring Dependencies Are Actually Ready Before Tests Run
Just as with a normal application startup, integration test dependencies need to be confirmed ready, not just started, before the tests that depend on them actually begin.
services:
app:
depends_on:
db:
condition: service_healthy
db:
image: postgres:16
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
Cleaning Up Integration Test Dependencies After the Run
Tearing down the test-specific Compose stack after the integration tests complete keeps the CI environment clean for subsequent runs.
docker compose -f docker-compose.test.yml down -v
Why CI Integration Dependencies Matter
Providing genuine, properly configured dependency services specifically for integration testing within CI allows this category of test to actually verify the application's real interaction with its dependencies, providing assurance that unit tests alone, with their mocked dependencies, cannot.