Parallelise groups of test

I’ve a suite of integration tests in a project that takes a long time to run. I’d like to try to speed this up and run multiple tests at the same time.

I can’t simply fork the test process because the test use a database and would create inconsistent results if truly parallelised. I’ve split the tests into a series of manageable groups and create separate Test tasks for each that use a combination of system properties and test filters to allow them to run indepentently.

What I can’t figure out is how to run these separate tasks in parallel. They are all in the same project so --parallel doesn’t help. I’ve tried the configuration-cache as AFAIK it’s supposed to allow this scenario but the tasks are still executed sequentially. Is there any way to tell why the configuration-cache doesn’t think these can be parallelised or some other way I can get the behaviour I’d like?

TIA
Craig

Indeed, if you use the configuration cache, all tasks that do not depend on each other can be run in parallel.
Tasks should only be run sequentially if there is some dependency or ordering constraint, or if they use the same shared build service with restricted parallelity.

Besides that, I personally would usually always prefer to not parallelize tests on Gradle side, but on the test engine side. So if you for example use Spock, or Jupiter, those support parallel test execution, including ability to lock resources so that tests that need the same resource and thus cannot be run in parallel are not run in parallel, while best leveraging available resources.

1 Like