Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle : Multiple configurations for Test tasks

I have got two types of tests in my app as follows:

  • Unit tests (large number of tests and quick to execute)
  • Integration tests (small number of tests but each suite takes considerable time)

My project uses gradle and I want both sets of tests to execute concurrently. As per gradle's documentation, I can use maxParallelForks config to parallelize the execution. However, as gradle distributes tasks to workers statistically (see here) there is a chance that all my integration tests get allocated to the same worker.

So, what I really want is to have two sets of test blocks in my gradle file, e.g.:

test {
    include 'org/unit/**'
    exclude 'org/integration/**'
    maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
}

test {
    include 'org/integration/**'
    exclude 'org/unit/**'
    maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
}

Does gradle support two different test profiles like the above? If yes, can I execute those two in parallel?

like image 688
Darshan Mehta Avatar asked Oct 20 '25 12:10

Darshan Mehta


1 Answers

I am assuming you have them all under the same source set: src/main/java/test.

I'd suggest creating a separate source set and task specifically for integration tests. See Configuring integration tests.

And since you want to parallelize the execution, then you'll need to create a custom task that submits both your unit and integration test tasks to the Worker API: https://guides.gradle.org/using-the-worker-api/

like image 105
Francisco Mateo Avatar answered Oct 22 '25 02:10

Francisco Mateo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!