The release of JUnit 5.3 introduces the concept of parallel test execution to the world of JUnit Jupiter. With this feature, it's possible to run multiple test cases in different threads concurrently. In this lesson, we are going to see how to prepare a project for parallel test execution, and explore the benefits of concurrency against a remarkably slow test class.
Enabling parallel tests is a two-part job: First, a configuration parameter is required for the TestEngine to recognize the demand. Second, the
@Execution annotation can be used to toggle the execution mode of a test class. As an alternative to the second step, concurrent execution can truly be used as the default for a test suite with another configuration parameter.
- Enable parallelism with the configuration parameter
- Annotate classes with
@Execution(CONCURRENT)to mark them as eligible for parallel execution
- To set parallel execution as the global default, use the configuration parameter