How can I stop JUnit?


 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,

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 {
catch (ProcessCanceledException e) {
// This line, why wrap the exception as MessageError
catch (ExecutionException t) {
logger.warn(logFailureMessage, t);
catch (Throwable t) {
logger.error(logFailureMessage, t);
return promise;
Is there any way to stop a junit without any abnormal prompts to the user?



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


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.


I don't think it's possible currently. 



Please sign in to leave a comment.