use of org.junit.jupiter.api.TestInstance.Lifecycle in project junit5 by junit-team.
the class TestInstanceLifecycleUtils method getDefaultTestInstanceLifecycle.
static TestInstance.Lifecycle getDefaultTestInstanceLifecycle(ConfigurationParameters configParams) {
Preconditions.notNull(configParams, "ConfigurationParameters must not be null");
String propertyName = DEFAULT_TEST_INSTANCE_LIFECYCLE_PROPERTY_NAME;
Optional<String> optional = configParams.get(propertyName);
String constantName = null;
if (optional.isPresent()) {
try {
constantName = optional.get().trim().toUpperCase();
Lifecycle lifecycle = TestInstance.Lifecycle.valueOf(constantName);
logger.info(() -> String.format("Using default test instance lifecycle mode '%s' set via the '%s' configuration parameter.", lifecycle, propertyName));
return lifecycle;
} catch (Exception ex) {
// local copy necessary for use in lambda expression
String constant = constantName;
logger.warn(() -> String.format("Invalid test instance lifecycle mode '%s' set via the '%s' configuration parameter. " + "Falling back to %s lifecycle semantics.", constant, propertyName, Lifecycle.PER_METHOD.name()));
}
}
return Lifecycle.PER_METHOD;
}
use of org.junit.jupiter.api.TestInstance.Lifecycle in project junit5 by junit-team.
the class TestInstanceLifecycleUtilsTests method assertDefaultConfigParam.
private void assertDefaultConfigParam(String configValue, Lifecycle expected) {
ConfigurationParameters configParams = mock(ConfigurationParameters.class);
when(configParams.get(KEY)).thenReturn(Optional.ofNullable(configValue));
Lifecycle lifecycle = getDefaultTestInstanceLifecycle(configParams);
assertThat(lifecycle).isEqualTo(expected);
}
use of org.junit.jupiter.api.TestInstance.Lifecycle in project junit5 by junit-team.
the class TestInstanceLifecycleUtilsTests method getTestInstanceLifecycleWithLocalConfigThatOverridesCustomDefaultSetViaConfigParam.
@Test
void getTestInstanceLifecycleWithLocalConfigThatOverridesCustomDefaultSetViaConfigParam() {
ConfigurationParameters configParams = mock(ConfigurationParameters.class);
when(configParams.get(KEY)).thenReturn(Optional.of(PER_CLASS.name().toLowerCase()));
Lifecycle lifecycle = getTestInstanceLifecycle(TestCase.class, configParams);
assertThat(lifecycle).isEqualTo(PER_METHOD);
}
use of org.junit.jupiter.api.TestInstance.Lifecycle in project junit5 by junit-team.
the class TestInstanceLifecycleUtilsTests method getDefaultTestInstanceLifecycleWithNoConfigParamSet.
@Test
void getDefaultTestInstanceLifecycleWithNoConfigParamSet() {
Lifecycle lifecycle = getDefaultTestInstanceLifecycle(mock(ConfigurationParameters.class));
assertThat(lifecycle).isEqualTo(PER_METHOD);
}
use of org.junit.jupiter.api.TestInstance.Lifecycle in project junit5 by junit-team.
the class TestInstanceLifecycleUtilsTests method getTestInstanceLifecycleFromSpecializedClassWithNoConfigParamSet.
@Test
void getTestInstanceLifecycleFromSpecializedClassWithNoConfigParamSet() {
Class<?> testClass = SpecializedTestCase.class;
Lifecycle lifecycle = getTestInstanceLifecycle(testClass, mock(ConfigurationParameters.class));
assertThat(lifecycle).isEqualTo(PER_CLASS);
}
Aggregations