TransWikia.com

Gradle. Running tests in parallel from one Class

Stack Overflow Asked on December 13, 2021

Using Java 11, Gradle 6.5.1

In the build.gradle there is an option:

maxParallelForks = 8

I have two classes, first has 2 tests and second has 30 tests.
When I run tests using Gradle it runs only in 2 threads:

./gradlew clean test

One thread – tests for the first class, second thread – tests for the second class.

But, how to make Gradle to execute all tests in parallel?
So tests from the same class could be run in parallel in 8 threads.

One Answer

If you're using JUnit 5, you can do this using JUnit's parallel execution instead of Gradle's. Note that this will be within the same JVM (I believe Gradle's maxParallelForks uses separate JVMs).

E.g. in your Gradle script:

test {
    ...... (your existing stuff here)
    systemProperties = [
        'junit.jupiter.execution.parallel.enabled': 'true'
        'junit.jupiter.execution.parallel.mode.default': 'concurrent'
    ]
}

Different test frameworks may have equivalents.


Other than that, a workaround might be to split your tests into a separate class per test case. You can use things like test class inheritance to avoid duplication with this.

If you have more than the 2 test classes you've mentioned here, you'd only need to split up the few longest running classes to get most of the benefit.

Answered by just me on December 13, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP