Skip to content

skillTesting

Integration Testing

Writes integration tests that use real databases and services, each with isolated data and fixed setup, so they are trustworthy and repeatable.

npx workspacetemplates add integration-testing --tool claude-code

Writes 1 file to .claude/skills/integration-testing/

.claude/skills/integration-testing/SKILL.md29 lines · 1.8 KBFile
---
name: integration-testing
description: Writes integration tests that use real databases and services, each with isolated data and fixed setup, so they are trustworthy and repeatable.
---

# Integration testing

Test the seams: your code against the real database, queue, cache or HTTP service.

## Steps

1. Pick the seams worth covering: repositories and migrations, HTTP routes with the real middleware, message consumers, clients of external APIs. Leave pure logic to unit tests.
2. Provide real dependencies. Use Testcontainers or docker compose with pinned image versions that match production. For third-party HTTP services use a local fake server or recorded fixtures (WireMock, nock, MSW), never the live service.
3. Setup once per run: start containers, apply real migrations, wait for readiness by health check, not by sleep.
4. Isolate each test: wrap it in a transaction that rolls back, or truncate touched tables, or give each worker its own schema. Create the data the test needs inside the test with small factory helpers. No shared fixtures that tests mutate.
5. Make time and randomness deterministic: inject a clock, seed generators, fix the time zone and locale.
6. Assert on observable results: rows stored, response status and body, messages published. Avoid asserting on SQL text or call counts.
7. Test failure paths too: unique violation, timeout, a 500 from the fake service, a retry.
8. Keep it quick: reuse the container, run files in parallel when data is isolated, and tag slow tests so they run in CI.

## Rules

- No `sleep` for synchronization; poll with a timeout.
- Tests must pass in any order and when run alone.
- Never point a test at a shared or production database.

## Report

Seams covered, the setup used, how isolation works, run time, and flakiness checks (run the suite three times).

What it does

Unit tests with every collaborator mocked cannot tell you whether the SQL runs, the migration applied or the HTTP client sends what the other side expects. Integration tests cover that gap, as long as they are deterministic.

This skill builds them around real dependencies, usually in containers, and gives each test its own data so order never matters. It also keeps the suite fast enough that people still run it before pushing.

Example

you › Add integration tests for the invoice repository and POST /invoices.

agent › Added tests using a Postgres 16 container with real migrations. 9 tests: insert, unique number conflict, tenant isolation, rollback on line item failure, and POST /invoices happy path, validation error, duplicate, and auth failure. Each test runs in a rolled back transaction. Suite takes 6.8 s and passed 3 runs in random order.

Questions

Why not use SQLite instead of the real database?
Different engines differ in types, locking and SQL features, so passing there proves little. A pinned container of your actual database is close to free now.
How do I stop slow tests from putting people off?
Share one container per run, isolate with transactions, parallelize by file and keep the heaviest cases behind a tag that CI runs.
  • Contract Testing

    SkillTesting

    Free
  • E2E Test Design

    SkillTesting

    Free
  • Flaky Test Diagnosis

    SkillTesting

    Free