Course contentsShow
← Software Engineering
Lesson 539 of 1,93316. Integration TestingFree lesson

CI/CD Integration with Real Dependencies

Configuring continuous integration pipelines to provision and tear down real dependencies for integration test runs.

CI/CD Integration with Real Dependencies

What you'll learn: How to automatically provision and clean up real dependencies (databases, message brokers, etc.) in your CI/CD pipeline for integration test runs.

The Challenge of Real Dependencies in CI

When your integration tests use real dependencies like databases or message brokers, your CI/CD pipeline needs to make those services available temporarily—just for the test run. You can't rely on a shared test database that persists between builds, because different builds might run in parallel or leave data behind.

The Core Idea

Your CI pipeline should treat real dependencies as ephemeral resources: spin them up before tests run, let the tests use them, then tear them down immediately after. This keeps each test run isolated and repeatable.

Think of it like renting a hotel room: you check in when you arrive (provision), use it during your stay (run tests), then check out and leave it clean for the next guest (tear down). Nobody wants to find the previous guest's belongings in their room.

How It Works

Modern CI systems let you define steps in your pipeline:

  1. Provision step: Start containers or cloud resources for your dependencies (database, message queue, etc.)
  2. Wait step: Ensure services are healthy and accepting connections
  3. Test step: Run your integration tests against the real dependencies
  4. Teardown step: Stop and remove all provisioned resources (usually in a finally or post block so it runs even if tests fail)

Tools like Docker Compose, Testcontainers, or cloud-native solutions handle the lifecycle automatically within your pipeline configuration.

Why This Matters

This approach gives you production-like confidence in CI while maintaining test isolation. Each pipeline run gets a fresh environment, preventing flaky tests from leftover state.

Key Takeaway: Configure your CI/CD pipeline to automatically provision real dependencies before integration tests and tear them down afterward, ensuring isolated, repeatable test environments for every build.