After enabling parallel test execution, JUnit Jupiter can be asked to use one of three strategies to determine the concurrency of our test suite. These strategies take different approaches to configure the environment of the parallel execution, such as the number of threads to use.
In this lesson, the most versatile and complex strategy, custom, is presented. For developers that seek complete control over their concurrent execution, the implementation of a
ParallelExecutionConfiguration is exposed to the TestEngine. This also provides a mechanism to consume custom configuration parameters passed to the JVM through the public API of the
To write a custom execution strategy, a dependency on the
junit-platform-engine library is required inside the test project; it houses the class definition of the
Strategy interface. After declaring the implementation, a configuration parameter feeds the fully-qualified class name to the Jupiter TestEngine, which will instantiate the custom strategy & use its settings to determine concurrency.
- Custom connects to an implementation of
- To set this strategy explicitly, use configuration parameter
- Use configuration parameter
junit.jupiter.execution.parallel.config.custom.classand set it to the FQCN of the implementation class
- If the strategy requires more external data, it can define its own configuration parameters. The name is arbitrary, but it must start with the