Can I run TestNG tasks in parallel (single build project)

I my build file have multiple TestNG tasks like:

task testsA(type: Test) {
    options.suites("src/test/resources/testng.xml") 
    reports {
        junitXml.outputPerTestCase = true
    }
    reports.junitXml.destination = "$buildDir/results/A"
}

task testsB(type: Test) {
    options.suites("src/test/resources/testng.xml") 
    reports {
        junitXml.outputPerTestCase = true
    }
    reports.junitXml.destination = "$buildDir/results/B"
}

And I have this also in build file:
tasks.withType(Test) {
useTestNG(){ }
}

Can I run testsA & testsB in parallel.

I tried using maxParallelForks = Runtime.runtime.availableProcessors() / 2 but this eventually run multiple tests within same task (let say testsA) in parallel.

What I am looking for is to run testsA & testsB simultaneously in parallel.

Task level parallelism is unsupported and undocumented feature that can easily cause unreproducible build failures unless you are very careful. There is a hidden flag to enable it, but you shouldn’t use it. I think they are going to bring it for real when Gradle transitions to the new configuration model.

What is your issue with having each test task execute the actual tests in parallel (i.e. why is maxParallelForks not sufficient for what you need)?

Thanks @ddimitrov for quick response, really appreciated…!!!

maxParallelForks is I think for running multiple TestNG tests annotated with @Test.

Problem is the structure of my project where I have only one test @Test which uses @DataProvider(name = “nameOfDataProvider”).

And all Gradle Test type task uses same @Test and @DataProvider to run multiple xml test case files structed in diffrent directories.

Now when I ran my tests with:
tasks.withType(Test) {
maxParallelForks = Runtime.runtime.availableProcessors() / 2
useTestNG(){ }
}

It just ran same test multiple times. Like testsA Gradle task has 4 tests in original, But it ran:
8 tests completed, 2 failed

Without maxParallelForks it runs
4 tests completed, 1 failed

I tried with hidden property as well -Dorg.gradle.parallel.intra=true. But it doesn’t help either.

So is there any any way I can run testsA & testsB in parallel?

As of now Gradle does not support running tasks within the same project in parallel.

The best you can do is to try to reframe your requirement. Alternatively, you will spend a lot of time fighting the tool and your colleagues will hate you when they have to maintain that build few years from now.

One way to do that is to merge the two test tasks, so they get parallelized. The downside is that then you can’t run one without the other.

More sophisticated (and obfuscated) way to do that is to change the build 2 empty tasks finalized by the test task and configure the test roots based on which of the test tasks are present in the TaskGraph. I would avoid this kind of things if possible and rather wait for the tool to provide the functionality (hopefully soon with Gradle 3.x).

This is the only (fully experimental) way of doing this atm. If you don’t see those tasks been executed in parallel you might have a dependency declared among them?

cheers,
René

@manoj7shekhawat Did you managed to find a way how to run specific XML test suite from command line? I tried your way and it gives me an error. Also you are using "reports.junitXml.destination = “$buildDir/results/A” with a TestNG framework.

Regards