Prompt
How do I run integration tests as part of CI?
Latest observation
Oct 19, 2026
OpenAI APIWeb search: off
To run integration tests in CI, the usual pattern is:
-
Make integration tests a separate test suite
- Keep them distinct from unit tests.
- Common names:
integration/tests/integration/*IT,*IntegrationTest, etc.
-
Ensure CI has the required dependencies Integration tests often need:
- a database
- Redis
- message broker
- external service mock/stub
- environment variables / secrets
In CI, you usually provide these via:
- Docker Compose
- service containers
- testcontainers
- mocked APIs
-
Run them in a dedicated CI job or stage Typical pipeline structure:
- lint
- unit tests
- build
- integration tests
- deploy
-
Use a clean, repeatable environment Integration tests should start from a known state:
- create fresh test DB
- reset fixtures between runs
- seed data as needed
- run migrations automatically
-
Fail the pipeline if they fail Integration tests should block merge/deploy, just like unit tests.
Example CI patterns
GitHub Actions
name: CI
on: [push, pull_request]
jobs:
unit-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run unit tests
run: ./gradlew test
integration-tests:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:16
env:
POSTGRES_USER: test
POSTGRES_PASSWORD: test
POSTGRES_DB: app_test
ports:
- 5432:5432
options: >-
--health-cmd="pg_isready -U test -d app_test"
--health-interval=10s
--health-timeout=5s
--health-retries=5
steps:
- uses: actions/checkout@v4
- name: Run integration tests
env:
DB_HOST: localhost
DB_PORT: 5432
DB_USER: test
DB_PASSWORD: test
run: ./gradlew integrationTest
GitLab CI
stages:
- test
integration_tests:
stage: test
image: gradle:8-jdk17
services:
- postgres:16
variables:
POSTGRES_DB: app_test
POSTGRES_USER: test
POSTGRES_PASSWORD: test
script:
- ./gradlew integrationTest
Docker Compose approach
services:
app:
build: .
depends_on:
- db
db:
image: postgres:16
environment:
POSTGRES_DB: app_test
POSTGRES_USER: test
POSTGRES_PASSWORD: test
Then CI runs:
docker compose up -d db
./gradlew integrationTest
docker compose down -v
Good practices
- Separate unit vs integration test commands
- Keep integration tests deterministic
- Use timeouts/retries for slow startup dependencies
- Avoid hitting real third-party APIs in CI unless explicitly required
- Parallelize carefully if tests share the same DB or state
- Collect logs/artifacts when integration tests fail
If you want the best setup
A strong modern approach is:
- unit tests run on every PR
- integration tests run on every PR too, but in a separate job
- end-to-end tests run only on main/release branches or nightly
If you tell me your stack (for example: Node/Jest, Python/pytest, Java/Maven/Gradle, .NET, Go, etc.) and CI system (GitHub Actions, GitLab, Jenkins, Azure DevOps), I can give you an exact working config.