Hi all, in this article, I will explain to you how to use JUnit 5 Parallel Test Execution feature. This is an experimental feature of JUnit 5 and it will come from after JUnit 5.3. To enable parallel execution, simply set the junit.jupiter.execution.parallel.enabled configuration parameter to true in junit-platform.properties file.

Once parallel test execution property is enabled, the JUnit Jupiter engine will execute tests in parallel according to the provided configuration with declared synchronization mechanisms. Please note that the Capturing Standard Output/Error feature needs to enabled separately. For configuration and synchronization details you can go and read JUnit 5 official documentation.

Let’s start to write some code and experiment this new functionality.

First, you need to add below dependencies in your pom.xml

Then, you need to create a “junit-platform.properties” file and locate under test resources folder.

The content of the junit-platform.properties file is as follows:

You can set your parallel test execution strategy as fixed as well. It depends on you. You can check them here.

Then, you need to add at the top of your test classes this annotation:  @Execution(ExecutionMode.CONCURRENT)

Also, you can add this annotation on top of the BaseTest class. In this way, you do not need to add this annotation at the top of each test classes.

A sample test class is shown below:

After these settings, when you run your tests they will run in parallel as shown below.

Here is the sample project repository: https://github.com/swtestacademy/junit5-parallel-testing