ContainerDeployable interface provides automated lifecycle management for services deployed as Docker containers using the Testcontainers framework.
Interface signature
Required methods
Returns the Testcontainers GenericContainer instance that this deployment manages. Implementations must provide the specific container instance.
Default methods
deploy()
Starts the container and logs deployment status.The service name is automatically derived from the implementing class name by removing the “Local” prefix.
undeploy()
Stops the container if it’s currently running.getLogs()
Retrieves the container logs for debugging purposes.Example implementation
Here’s how to implement a PostgreSQL service usingContainerDeployable:
Usage in tests
Register the deployment as a JUnit extension:The
ContainerDeployable interface extends Deployable, which implements JUnit’s BeforeAllCallback and AfterAllCallback. This ensures containers are automatically started before tests and stopped afterward.Related interfaces
- Deployable - Base interface for all deployments
- OpenshiftDeployable - For OpenShift-based deployments
- RemoteService - For external service connections