Integration Testing
Purpose
Verify that units work together across real boundaries — services + data layer + wiring, with a real database and faked externals — so bugs that live between components (not inside them) are caught. Broader than pure unit tests; the HTTP-endpoint specialization is api-integration-testing.
When to Use
- For behavior spanning modules and I/O: service → repository → database, job pipelines, multi-module workflows.
- Not for pure logic (
unit-testing) or full browser/device journeys (playwright-e2e/maestro-e2e).
Inputs
- Runner (Jest/Vitest —
testing-selection), real datastore for tests (test-environment-management), seed/factory strategy (test-data-management).
- The workflow under test and its authorization rules.
Discovery Questions
- What real boundaries must participate (DB, cache, queue) vs be faked (third-party APIs)?
- How does a test get an isolated real datastore per run/test?
- Which workflows carry authorization rules that must be verified, not assumed?
Responsibilities
- Take the behavior to be covered from its Gherkin scenarios (
gherkin-specifications) — implement one test per scenario rather than inventing a parallel case list.
- Exercise the real wiring: real database (same engine as production — never SQLite-for-Postgres), real repositories/services; fake only true externals (
../../backend/third-party-integrations interfaces).
- Cover the required cases per workflow: happy path, invalid input (rejected at the right boundary), error path (dependency failure handled, no partial state —
../../database/transactions), and authorization denial (an actor lacking rights is refused — ../../backend/backend-authorization).
- Manage data with factories + isolation (
test-data-management), so tests own their state and don't depend on order.
- Assert observable outcomes: returned values, persisted state, emitted effects — not internal calls.
- Keep the suite hermetic and parallelizable; wire as a CI tier (
../../devops/ci-cd).
Required Workflow
- Choose real-vs-faked boundaries for the workflow.
- Set up isolated real datastore + factories.
- Cover happy / invalid-input / error-path / authorization-denial.
- Assert persisted + returned state; verify no partial writes on failure.
- Wire into CI; keep runtime bounded.
Decision Rules
- Same datastore engine as production, always — engine differences hide real bugs.
- Authorization denial is a required integration case wherever rules exist — a missing denial test is a missing control.
- Fake externals at your own interface, not by mocking the data layer (that would make it a slow unit test).
- Isolation via transaction-rollback or truncate-per-test; no shared mutable seed database.
Rules
- No real third-party calls or emails from tests.
- Tests own their data; no execution-order dependence.
- Fixes at this layer land with regression tests (
regression-testing).
Anti-Patterns
- Mocking the database in an "integration" test.
- Covering happy paths only; skipping error and authorization-denial cases.
- One shared seeded DB mutated across the suite.
- Asserting exact error strings instead of codes/shapes.
- SQLite standing in for the production engine.
Validation Checklist
Definition of Done
An integration suite exercising real wiring and a production-engine datastore, covering happy, invalid-input, error, and authorization-denial paths per workflow — hermetic, isolated, and CI-gating.
Related Skills
testing-selection, unit-testing, api-integration-testing, test-data-management, test-environment-management, regression-testing, ../../backend/backend-authorization, ../../database/transactions, ../../devops/ci-cd.
Related Knowledge
../../../knowledge/ (workflows, authorization rules).
Related References
../../../references/testing/ (patterns, when populated).
Context Loading Guidance
- Requires: the workflow + its authorization rules, datastore/factory strategy.
- Does not require: unit internals, full app source, unrelated workflows.
- May load:
test-data-management, api-integration-testing.
- Stop when: the workflow's required cases pass hermetically.
Token Efficiency Guidance
Drive coverage from the workflow × required-case matrix; read the workflow's modules, not the whole app.
1---2name: integration-testing3description: Use to plan integration tests across module and I/O boundaries — real database, real wiring, faked externals — covering happy path, invalid input, error path, and authorization denial. For HTTP API specifics use api-integration-testing.4---56# Integration Testing78## Purpose910Verify that units work **together across real boundaries** — services + data layer + wiring, with a real database and faked externals — so bugs that live between components (not inside them) are caught. Broader than pure unit tests; the HTTP-endpoint specialization is `api-integration-testing`.1112## When to Use1314- For behavior spanning modules and I/O: service → repository → database, job pipelines, multi-module workflows.15- **Not** for pure logic (`unit-testing`) or full browser/device journeys (`playwright-e2e`/`maestro-e2e`).1617## Inputs1819- Runner (Jest/Vitest — `testing-selection`), real datastore for tests (`test-environment-management`), seed/factory strategy (`test-data-management`).20- The workflow under test and its authorization rules.2122## Discovery Questions2324- What real boundaries must participate (DB, cache, queue) vs be faked (third-party APIs)?25- How does a test get an isolated real datastore per run/test?26- Which workflows carry authorization rules that must be verified, not assumed?2728## Responsibilities2930- Take the behavior to be covered from its **Gherkin scenarios** (`gherkin-specifications`) — implement one test per scenario rather than inventing a parallel case list.31- Exercise the **real wiring**: real database (same engine as production — never SQLite-for-Postgres), real repositories/services; fake only true externals (`../../backend/third-party-integrations` interfaces).32- Cover the **required cases** per workflow: **happy path**, **invalid input** (rejected at the right boundary), **error path** (dependency failure handled, no partial state — `../../database/transactions`), and **authorization denial** (an actor lacking rights is refused — `../../backend/backend-authorization`).33- Manage data with factories + isolation (`test-data-management`), so tests own their state and don't depend on order.34- Assert observable outcomes: returned values, persisted state, emitted effects — not internal calls.35- Keep the suite hermetic and parallelizable; wire as a CI tier (`../../devops/ci-cd`).3637## Required Workflow38391. Choose real-vs-faked boundaries for the workflow.402. Set up isolated real datastore + factories.413. Cover happy / invalid-input / error-path / authorization-denial.424. Assert persisted + returned state; verify no partial writes on failure.435. Wire into CI; keep runtime bounded.4445## Decision Rules4647- Same datastore engine as production, always — engine differences hide real bugs.48- Authorization denial is a **required** integration case wherever rules exist — a missing denial test is a missing control.49- Fake externals at your own interface, not by mocking the data layer (that would make it a slow unit test).50- Isolation via transaction-rollback or truncate-per-test; no shared mutable seed database.5152## Rules5354- No real third-party calls or emails from tests.55- Tests own their data; no execution-order dependence.56- Fixes at this layer land with regression tests (`regression-testing`).5758## Anti-Patterns5960- Mocking the database in an "integration" test.61- Covering happy paths only; skipping error and authorization-denial cases.62- One shared seeded DB mutated across the suite.63- Asserting exact error strings instead of codes/shapes.64- SQLite standing in for the production engine.6566## Validation Checklist6768- [ ] Real boundaries participate; externals faked at interfaces.69- [ ] Happy + invalid-input + error-path + authorization-denial covered.70- [ ] Isolated real datastore; factory-driven data.71- [ ] Persisted + returned state asserted; no partial writes on failure.72- [ ] Hermetic, parallel, CI-wired.7374## Definition of Done7576An integration suite exercising real wiring and a production-engine datastore, covering happy, invalid-input, error, and authorization-denial paths per workflow — hermetic, isolated, and CI-gating.7778## Related Skills7980`testing-selection`, `unit-testing`, `api-integration-testing`, `test-data-management`, `test-environment-management`, `regression-testing`, `../../backend/backend-authorization`, `../../database/transactions`, `../../devops/ci-cd`.8182## Related Knowledge8384`../../../knowledge/` (workflows, authorization rules).8586## Related References8788`../../../references/testing/` (patterns, when populated).8990## Context Loading Guidance9192- **Requires:** the workflow + its authorization rules, datastore/factory strategy.93- **Does not require:** unit internals, full app source, unrelated workflows.94- **May load:** `test-data-management`, `api-integration-testing`.95- **Stop when:** the workflow's required cases pass hermetically.9697## Token Efficiency Guidance9899Drive coverage from the workflow × required-case matrix; read the workflow's modules, not the whole app.