How can I stop JUnit?

Answered

 version '2021.2.3'

I have developed a plugin. I hope that the first junit will run normally, the second run will stop directly, and it will be run by the thread of the first run.

When I stopped junit for the second time,I use the JavaProgramPatcher,

@Override
public void patchJavaParameters(Executor executor, RunProfile configuration, JavaParameters javaParameters) {
throw new ProcessCanceledException(new RunCanceledByUserException());
}

The second test stopped normally, but he signaled an exception, and I didn't want him to.

I read the code in TargetEnvironmentAwareRunProfileState line 53,The exception is packaged as MessageError, so he will prompt.

return preparationTasks.thenAsync((Object o) -> {
AsyncPromise<@Nullable T> promise = new AsyncPromise<>();
AppExecutorUtil.getAppExecutorService().execute(() -> {
try {
promise.setResult(afterPreparation.compute());
}
catch (ProcessCanceledException e) {
// This line, why wrap the exception as MessageError
promise.setError(StringUtil.notNullize(e.getLocalizedMessage()));
}
catch (ExecutionException t) {
logger.warn(logFailureMessage, t);
promise.setError(t);
}
catch (Throwable t) {
logger.error(logFailureMessage, t);
promise.setError(t);
}
});
return promise;
});
 
Is there any way to stop a junit without any abnormal prompts to the user?
 
 

 

0
3 comments

Could you please explain what is the use-case/goal of this plugin? Who and why/when does it stop running tests?

0

goal of this plugin:

When I run spring-related junit, all spring-related classes will be restarted every time I run it, which will cause repeated junit operation to be very slow. When this plug-in runs junit for the second time, it does not need to restart all spring related classes, and directly uses the classes started for the first time.

 

Who and why/when does it stop running tests:

When running junit for the second time, switch directly to the view of the first run, so just stop the second time.

0

I don't think it's possible currently. 

Anna

0

Please sign in to leave a comment.