Testcontainers
Last updated
© Leapwise
Last updated
Testcontainers is an open-source framework that provides disposable, lightweight instances of databases, message brokers, web browsers, or virtually anything that can run in a Docker container. With Testcontainers, you can write tests that depend on the same services used in production, without the need for mocks or in-memory services. Figure 1 shows how all My Service dependencies can be replaced with the testcontainers.
You can use Testcontainers with any testing library you are already familiar with. A typical Testcontainers-based integration test works as follows:
Before Test execution: Start your required services (databases, messaging systems etc.) as Docker containers using the Testcontainers API. Once the required containers start, configure or update your application configuration to use these containerized services and optionally initialize data needed for the test.
During Test execution: Your tests run using these containerized services.
After Test execution: Testcontainers takes care of destroying containers irrespective