-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Description
<junit-jupiter.version>5.10.1</junit-jupiter.version>
<junit-platform.version>1.10.1</junit-platform.version> public static void runSuit(TestContext context, Class<?> clazz){
try (LauncherSession session = LauncherFactory.openSession()) {
Launcher launcher = session.getLauncher();
DiscoveryStart discoveryStart = new DiscoveryStart(clazz, context.getSteps().toArray(new String[0]));
LauncherDiscoveryRequest request = discoveryStart.request();
TestPlan testPlan = launcher.discover(request);
ExecutionActionListenerPlus executionActionListenerPlus = new ExecutionActionListenerPlus();
launcher.registerTestExecutionListeners(executionActionListenerPlus);
LauncherDiscoveryListener launcherDiscoveryListener = LauncherDiscoveryListeners.abortOnFailure();
launcher.registerLauncherDiscoveryListeners(launcherDiscoveryListener);
SummaryGeneratingListener summaryGeneratingListener = new SummaryGeneratingListener();
launcher.execute(request, summaryGeneratingListener);
}
} public class ExecutionActionListenerPlus implements TestExecutionListener {
@Override
public void executionFinished(TestIdentifier testIdentifier, TestExecutionResult testExecutionResult) {
switch (testExecutionResult.getStatus()) {
case SUCCESSFUL:
break;
case ABORTED:
break;
case FAILED:
testExecutionResult.getThrowable().ifPresent((throwable) -> {
try {
throw throwable.getCause();
} catch (Throwable e) {
throw new TestException(e.getMessage());
}
});
break;
default:
break;
}
}
}I execute two test methods in a class, and expect the first test method to terminate execution if it encounters an exception, while the second test method will no longer execute; Actually, the second test method was still executed.
I think this breaks the agreement on the testing lifecycle.
My test component, some tests in a class have dependencies.I don't know how to solve this problem.
I think this is a bug because execution is uncontrollable and it wastes time and resources when executing large batches of cases