use of org.junit.jupiter.api.TestInstance.Lifecycle in project junit5 by junit-team.
the class TestInstanceLifecycleUtilsTests method getTestInstanceLifecycleFromMetaAnnotationWithNoConfigParamSet.
@Test
void getTestInstanceLifecycleFromMetaAnnotationWithNoConfigParamSet() {
Class<?> testClass = BaseMetaAnnotatedTestCase.class;
Lifecycle lifecycle = getTestInstanceLifecycle(testClass, mock(ConfigurationParameters.class));
assertThat(lifecycle).isEqualTo(PER_CLASS);
}
use of org.junit.jupiter.api.TestInstance.Lifecycle in project junit5 by junit-team.
the class TestInstanceLifecycleUtilsTests method getTestInstanceLifecycleWithConfigParamSet.
@Test
void getTestInstanceLifecycleWithConfigParamSet() {
ConfigurationParameters configParams = mock(ConfigurationParameters.class);
when(configParams.get(KEY)).thenReturn(Optional.of(PER_CLASS.name().toLowerCase()));
Lifecycle lifecycle = getTestInstanceLifecycle(getClass(), configParams);
assertThat(lifecycle).isEqualTo(PER_CLASS);
}
use of org.junit.jupiter.api.TestInstance.Lifecycle in project junit5 by junit-team.
the class TestInstanceLifecycleUtilsTests method getTestInstanceLifecycleWithNoConfigParamSet.
@Test
void getTestInstanceLifecycleWithNoConfigParamSet() {
Lifecycle lifecycle = getTestInstanceLifecycle(getClass(), mock(ConfigurationParameters.class));
assertThat(lifecycle).isEqualTo(PER_METHOD);
}
use of org.junit.jupiter.api.TestInstance.Lifecycle in project junit5 by junit-team.
the class ClassTestDescriptor method prepare.
// --- Node ----------------------------------------------------------------
@Override
public JupiterEngineExecutionContext prepare(JupiterEngineExecutionContext context) {
ExtensionRegistry registry = populateNewExtensionRegistryFromExtendWithAnnotation(context.getExtensionRegistry(), this.testClass);
// Register extensions from static fields here, at the class level but
// after extensions registered via @ExtendWith.
registerExtensionsFromFields(registry, this.testClass, null);
registerBeforeEachMethodAdapters(registry);
registerAfterEachMethodAdapters(registry);
Lifecycle lifecycle = getTestInstanceLifecycle(this.testClass, context.getConfigurationParameters());
ThrowableCollector throwableCollector = new ThrowableCollector();
ClassExtensionContext extensionContext = new ClassExtensionContext(context.getExtensionContext(), context.getExecutionListener(), this, lifecycle, context.getConfigurationParameters(), throwableCollector);
this.beforeAllMethods = findBeforeAllMethods(this.testClass, lifecycle == Lifecycle.PER_METHOD);
this.afterAllMethods = findAfterAllMethods(this.testClass, lifecycle == Lifecycle.PER_METHOD);
// @formatter:off
return context.extend().withTestInstanceProvider(testInstanceProvider(context, registry, extensionContext)).withExtensionRegistry(registry).withExtensionContext(extensionContext).withThrowableCollector(throwableCollector).build();
// @formatter:on
}
use of org.junit.jupiter.api.TestInstance.Lifecycle in project junit5 by junit-team.
the class ClassTestDescriptor method before.
@Override
public JupiterEngineExecutionContext before(JupiterEngineExecutionContext context) throws Exception {
Lifecycle lifecycle = context.getExtensionContext().getTestInstanceLifecycle().orElse(Lifecycle.PER_METHOD);
if (lifecycle == Lifecycle.PER_CLASS) {
// Eagerly load test instance for BeforeAllCallbacks, if necessary,
// and store the instance in the ExtensionContext.
ClassExtensionContext extensionContext = (ClassExtensionContext) context.getExtensionContext();
extensionContext.setTestInstance(context.getTestInstanceProvider().getTestInstance(Optional.empty()));
}
ThrowableCollector throwableCollector = context.getThrowableCollector();
invokeBeforeAllCallbacks(context);
if (throwableCollector.isEmpty()) {
context.beforeAllMethodsExecuted(true);
invokeBeforeAllMethods(context);
}
throwableCollector.assertEmpty();
return context;
}
Aggregations