#How to run JUnit test methods concurrently?

1 messages · Page 1 of 1 (latest)

proper moth
#

So I have a class I wanna test.
I want to start it from one method and stop it from another.
It takes aprox 4-5 seconds to run, but if I stop it while it's running it should stop earlier. Kinda like this

snow hatchBOT
#

<@&987246399047479336> please have a look, thanks.

snow hatchBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

proper moth
#
@Execution(ExecutionMode.CONCURRENT)
class TestSut {
    private ThaSut sut = new ThaSut();
     
    @Test
    @Execution(ExecutionMode.CONCURRENT)
    public void testStop() {
        try {
           Thread.currentThread().sleep(1000);
            sut.stopProcess();
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    @Test
    @Execution(ExecutionMode.CONCURRENT)
    void testStart() {
        sut.start(input); // this takes aprox 4-5 sec. So above test code should stop it earlier.
        File file = new File(output);       
        assertFalse(file.exists());
    }
snow hatchBOT
proper moth
#

I added a junit-platform.properties file in src/test/resources folder.

#

It has this content:

#
junit.jupiter.execution.parallel.enabled = true
junit.jupiter.execution.parallel.mode.default = concurrent