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 3
Required
Test against the same database engine
TST-12Test database code against the same database engine and version as production, never against a different engine or a mock.
Test how your code handles each outside service failing
TST-16Test what your code does when each outside service hangs, refuses the connection, answers with an error or sends an unexpected body. Nothing is lost or done twice.
Recommended
Fake only what you do not own
TST-13Replace only outside services, such as a payment provider or an email API, with test doubles. Run your own code as it runs in production.
Check the contract between services
TST-14When two services you own talk to each other, test the shape of their messages on both sides with a shared contract. This covers events sent through a queue or broker as well as requests.
Check that outside services still match your fakes
TST-15At least once a week, run a small test against each outside service to prove your fakes still behave like it.
Read this with
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/testing/integration-and-contract-tests">Agent Wranglers testing playbook</a>. In code you write, add a comment next to it with the same link.