Coding
AI Prompt for Integration Tests
Write solid integration tests with this AI prompt: end-to-end flows, isolated test data setup and teardown, and clear real-versus-mocked boundaries.
The prompt
Role: You are a test architect who designs integration tests that verify components work TOGETHER. Context: Stack: [STACK]. Flow to test: [FLOW_DESCRIPTION, step by step]. Test strategy: [STRATEGY: real DB / testcontainers / in-memory / mocked externals]. Task: 1) Design the test setup: what infrastructure spins up, test data seeding, and teardown that guarantees isolation between tests. 2) Write the tests for: the happy path end-to-end, plus [FAILURE_SCENARIOS, e.g. duplicate email, DB down, email service fails]. 3) Show how each external dependency is handled (real, containerized, or mocked) and justify the choice. 4) Note what is intentionally NOT covered (that's for unit or E2E tests). Format: Setup/teardown code first, then the tests, then the dependency decisions, then the not-covered list. Ask the AI to estimate the suite's runtime and to suggest a parallelization or tagging strategy if it exceeds two minutes. Slow integration suites get skipped, and skipped suites protect nothing. Constraints: Tests must be isolated — no shared state, no order dependence. Every test cleans up after itself. Prefer testing through public interfaces, not internals.
Variables to fill in
Replace each [variable] in the prompt with your own details:
[STACK] [FLOW_DESCRIPTION] [STRATEGY] [FAILURE_SCENARIOS]
Example input
FLOW=user registration: API → DB → welcome email, STACK=Node.js/Express/Postgres, STRATEGY=testcontainers for DB, mailhog for email, SCOPE=happy path + duplicate email
How to use this prompt
Describe the full flow step by step — integration tests verify the wiring between steps. State what is real vs mocked; that boundary defines the test.
Tips for the best results
- The setup/teardown design matters more than the assertions — review it first.
- Ask for the test runtime estimate; slow integration suites get skipped.
- Tag integration tests separately so unit tests stay fast.
Frequently asked questions
Do I need Docker knowledge for this?
It designs the strategy (what to spin up, what to mock) and writes the tests — you provide the flow and the stack.
How do I keep integration tests from being flaky?
Isolation: fresh data per test, no shared state, no order dependence. The prompt designs setup and teardown around that principle — review it first.