Interface for reusing OpenShift deployments across multiple tests
The ReusableOpenshiftDeployable interface enables resource reuse between test classes to avoid the overhead of repeated deployments and undeployments. Instead of tearing down services after each test class, they remain deployed and are cleaned up between tests.
Cleans up the service state between test runs without undeploying it. This should reset the service to a clean state (e.g., delete database tables, remove files, clear queues).
void cleanup();
The cleanup() method should be idempotent and safe to call multiple times.
Executed before each test class. Deploys the service if not already deployed and opens resources.
default void beforeAll(ExtensionContext extensionContext) throws Exception { // Deploy does "deploy" (if it is not already deployed) + wait until it's ready deploy(); openResources();}
The deploy() method checks if the service is already deployed before attempting deployment, enabling reuse.
public class DatabaseTest1 { @RegisterExtension static OpenshiftPostgreSQL postgres = new OpenshiftPostgreSQL(); @Test void testOperation1() { // First test class - deploys PostgreSQL Connection conn = postgres.getConnection(); // ... perform test operations }}public class DatabaseTest2 { @RegisterExtension static OpenshiftPostgreSQL postgres = new OpenshiftPostgreSQL(); @Test void testOperation2() { // Second test class - reuses existing PostgreSQL deployment Connection conn = postgres.getConnection(); // ... perform test operations }}
Reusing deployments can significantly reduce test execution time:
Traditional approach (5 test classes): Deploy (30s) + Test (10s) + Undeploy (10s) = 50s per class Total: 250sReusable approach (5 test classes): Deploy (30s) + Test (10s) + Cleanup (2s) = 42s for first class Reuse + Test (10s) + Cleanup (2s) = 12s for subsequent classes Total: 90s (64% faster)