12

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.

asked Sep 13, 2016 at 12:23
4
  • In this response it use a thrid party library to do so stackoverflow.com/questions/29312191/… but maybe it can help you. Commented Sep 13, 2016 at 12:31
  • Thanks for reminding, I have seen JUnit Toolbox. I was hoping for a native solution, especially with jUnit5 comming out pretty soon Commented Sep 13, 2016 at 12:41
  • As you mentioned, Gradle does not support parallel test execution at the method level. So if you want parallel execution of test methods within a single test class, you'll have to find an alternative solution that does not use Gradle's native testing support. Commented Sep 14, 2016 at 10:32
  • 2
    Regarding JUnit 5, there is currently no support for executing tests in parallel; however, there is an open issue to address this at a later date: github.com/junit-team/junit5/issues/60 Commented Sep 14, 2016 at 10:32

2 Answers 2

11

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.

sleske
84k40 gold badges195 silver badges238 bronze badges
answered Aug 12, 2020 at 19:37

6 Comments

Warning: Parallel test execution is an experimental feature
This is not what the original question asked for. JUnit 5 can parallelize by class (which would not achieve any parallelism in this case) or by method (which would parallelize too much). The original question was asking for one thread per input parameter.
@Doradus, this parallelizes execution per input parameter as requested. If it is undesirable to run other test methods on the same class in parallel with the parameterized one (OP have not specified that), they can be moved to a separate class and use junit.jupiter.execution.parallel.mode.classes.default = same_thread to run classes one-by-one.
@Doradus: It's not mentioned explicitly - however the docs say that "nodes in the test tree" are run concurrently, and apparently the different invocations of a parameterized test count as differend "nodes".
I edited to add that this can be enabled per test, not just globally.
|
1

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

answered Jun 21, 2019 at 7:58

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.