mathiasbn
mathiasbn

Reputation: 931

Running junit parameterized tests (not classes) in parallel

I have a parameterized junit integration-test. It has 30 inputs (giving it 30 tests to run) and each takes 18 sec.

I would like to run them in parallel.

I'm running them from gradle and they are currently written in jUnit4, but i'm ready to switch to jUnit5 if that helps.

At the moment I can use gradles maxParallelForks but that only forks on classes.

Upvotes: 10

Views: 9652

Answers (2)

Kirill
Kirill

Reputation: 8056

The feature is available since v 5.3

Create src/test/resources/junit-platform.properties with the following content:

junit.jupiter.execution.parallel.enabled = true

To actually run tests in parallel, you need to annotate the test with

@Execution(ExecutionMode.CONCURRENT)

Alternatively, you can set this as the default for all tests in junit-platform.properties:

# run test methods in parallel by default
junit.jupiter.execution.parallel.mode.default = concurrent

junit.jupiter.execution.parallel.mode.default will run test methods in the same class (including parameterized methods) in parallel.

There is also a junit.jupiter.execution.parallel.mode.classes.default to run tests from multiple classes in parallel. Check the picture in jUnit 5 docs to see the difference between 2 properties.

Upvotes: 9

Svilen
Svilen

Reputation: 1437

JUnit 5 has built-in support for running tests in parallel. The official documentation is undoubtedly the best source to check it out: https://junit.org/junit5/docs/snapshot/user-guide/#writing-tests-parallel-execution

Upvotes: 1

Related Questions