Best Testcontainers-java code snippet using org.testcontainers.junit.jupiter.TestcontainersExtensionTests.extensionContext
Source:TestcontainersExtensionTests.java
...9public class TestcontainersExtensionTests {10 @Test11 void whenDisabledWithoutDockerAndDockerIsAvailableTestsAreEnabled() {12 ConditionEvaluationResult result = new TestTestcontainersExtension(true)13 .evaluateExecutionCondition(extensionContext(DisabledWithoutDocker.class));14 assertFalse(result.isDisabled());15 }16 @Test17 void whenDisabledWithoutDockerAndDockerIsUnavailableTestsAreDisabled() {18 ConditionEvaluationResult result = new TestTestcontainersExtension(false)19 .evaluateExecutionCondition(extensionContext(DisabledWithoutDocker.class));20 assertTrue(result.isDisabled());21 }22 @Test23 void whenEnabledWithoutDockerAndDockerIsAvailableTestsAreEnabled() {24 ConditionEvaluationResult result = new TestTestcontainersExtension(true)25 .evaluateExecutionCondition(extensionContext(EnabledWithoutDocker.class));26 assertFalse(result.isDisabled());27 }28 @Test29 void whenEnabledWithoutDockerAndDockerIsUnavailableTestsAreEnabled() {30 ConditionEvaluationResult result = new TestTestcontainersExtension(false)31 .evaluateExecutionCondition(extensionContext(EnabledWithoutDocker.class));32 assertFalse(result.isDisabled());33 }34 private ExtensionContext extensionContext(Class clazz) {35 ExtensionContext extensionContext = mock(ExtensionContext.class);36 when(extensionContext.getRequiredTestClass()).thenReturn(clazz);37 return extensionContext;38 }39 @Testcontainers(disabledWithoutDocker = true)40 static final class DisabledWithoutDocker {41 }42 @Testcontainers43 static final class EnabledWithoutDocker {44 }45 static final class TestTestcontainersExtension extends TestcontainersExtension {46 private final boolean dockerAvailable;47 private TestTestcontainersExtension(boolean dockerAvailable) {48 this.dockerAvailable = dockerAvailable;49 }50 boolean isDockerAvailable() {51 return dockerAvailable;...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!