Jupiter / JUnit 5
This module provides an API that is based on the JUnit Jupiter extension model.
The extension supports two modes:
- containers that are restarted for every test method
- containers that are shared between all methods of a test class
Note that Jupiter/JUnit 5 integration is packaged as a separate library JAR; see below for details.
Extension
Jupiter integration is provided by means of the @Testcontainers annotation.
The extension finds all fields that are annotated with @Container and calls their container lifecycle
methods (methods on the Startable interface). Containers declared as static fields will be shared between test
methods. They will be started only once before any test method is executed and stopped after the last test method has
executed. Containers declared as instance fields will be started and stopped for every test method.
Note: This extension has only been tested with sequential test execution. Using it with parallel test execution is unsupported and may have unintended side effects.
Example:
@Testcontainers
class MixedLifecycleTests {