Search in sources :

Example 11 with ThrowableCollector

use of org.junit.jupiter.engine.execution.ThrowableCollector in project junit5 by junit-team.

the class TestMethodTestDescriptor method execute.

@Override
public JupiterEngineExecutionContext execute(JupiterEngineExecutionContext context, DynamicTestExecutor dynamicTestExecutor) throws Exception {
    ThrowableCollector throwableCollector = context.getThrowableCollector();
    // @formatter:off
    invokeBeforeEachCallbacks(context);
    if (throwableCollector.isEmpty()) {
        invokeBeforeEachMethods(context);
        if (throwableCollector.isEmpty()) {
            invokeBeforeTestExecutionCallbacks(context);
            if (throwableCollector.isEmpty()) {
                invokeTestMethod(context, dynamicTestExecutor);
            }
            invokeAfterTestExecutionCallbacks(context);
        }
        invokeAfterEachMethods(context);
    }
    invokeAfterEachCallbacks(context);
    // @formatter:on
    throwableCollector.assertEmpty();
    return context;
}
Also used : ThrowableCollector(org.junit.jupiter.engine.execution.ThrowableCollector)

Example 12 with ThrowableCollector

use of org.junit.jupiter.engine.execution.ThrowableCollector in project junit5 by junit-team.

the class TestMethodTestDescriptor method invokeBeforeMethodsOrCallbacksUntilExceptionOccurs.

private <T extends Extension> void invokeBeforeMethodsOrCallbacksUntilExceptionOccurs(JupiterEngineExecutionContext context, BiFunction<ExtensionContext, T, Executable> generator, Class<T> type) {
    ExtensionRegistry registry = context.getExtensionRegistry();
    ExtensionContext extensionContext = context.getExtensionContext();
    ThrowableCollector throwableCollector = context.getThrowableCollector();
    for (T callback : registry.getExtensions(type)) {
        Executable executable = generator.apply(extensionContext, callback);
        throwableCollector.execute(executable);
        if (throwableCollector.isNotEmpty()) {
            break;
        }
    }
}
Also used : ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) Executable(org.junit.jupiter.api.function.Executable) ExtensionRegistry(org.junit.jupiter.engine.extension.ExtensionRegistry) ThrowableCollector(org.junit.jupiter.engine.execution.ThrowableCollector)

Aggregations

ThrowableCollector (org.junit.jupiter.engine.execution.ThrowableCollector)12 ExtensionContext (org.junit.jupiter.api.extension.ExtensionContext)9 ExtensionRegistry (org.junit.jupiter.engine.extension.ExtensionRegistry)8 Method (java.lang.reflect.Method)3 Lifecycle (org.junit.jupiter.api.TestInstance.Lifecycle)2 Executable (org.junit.jupiter.api.function.Executable)2 TestInstanceLifecycleUtils.getTestInstanceLifecycle (org.junit.jupiter.engine.descriptor.TestInstanceLifecycleUtils.getTestInstanceLifecycle)2 BeforeEach (org.junit.jupiter.api.BeforeEach)1 AfterAllCallback (org.junit.jupiter.api.extension.AfterAllCallback)1 BeforeAllCallback (org.junit.jupiter.api.extension.BeforeAllCallback)1 JupiterEngineExecutionContext (org.junit.jupiter.engine.execution.JupiterEngineExecutionContext)1