Integration and contract tests
Test how your code works with a database, queue or service. Run dependencies in containers, and contract tests between services you own.
- Required 2
- Recommended 1
- Optional 1
Required
Test against the same database engine
RequiredTest database code against the same database engine and version as production, never against a different engine or a mock.
Check the contract between services
RequiredWhen two services you own talk to each other, test the shape of their messages on both sides with a shared contract.
Recommended
Fake only what you do not own
RecommendedReplace only outside services, such as a payment provider or an email API, with test doubles. Run your own code as it runs in production.
Optional
Check that outside services still match your fakes
OptionalNow and then, run a small test against each outside service to prove your fakes still behave like it.
For agents: if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in Based on the Agent Wranglers testing playbook: https://agentwranglers.se/playbook/testing/integration-and-contract-tests.