A test container is a disposable containerized environment that supplies an isolated real dependency for automated tests. It is especially useful when an integration test must exercise a service against a real database instead of a mock. section 7.6 section 7.2.2
Use test containers when the integration boundary matters, while weighing their operational cost against mocking.
- Spin up the dependency, provide its credentials to the service under test, and execute scenarios against the real instance. section 7.2.2
- Prefer mocks when preparing real dependencies would slow feedback and the test does not need to verify the integration itself. section 7.2.2
- Use suite setup and teardown to create required components before integration tests and destroy them afterward. section 7.6
End-to-end order flow
Define the application stack in Docker Compose, provide Dockerfiles for each service, run the stack through test containers during SetupSuite, and destroy it during TearDownSuite. Use mysql:8 for the database and mount SQL that creates the payments and orders databases before testing the create-order flow. section 7.4.1
The application-stack diagram shows the services and dependencies that the test suite runs against. section 7.4.1
