How to aggregate test reports when gradle build command is run in a loop

My scenario is like this -

I have to run multiple gradle build commands in a loop through shell script.

So For eg test.sh has the following -

for file in *; do
echo "$file"
fileName=$file
#echo "$fileName"
gradle build -Pear=$fileName -Phost=localhost -Pport=8080
done

Lets say gradle build command is executed 5 times. Each time it executes specific tests based on the fileName. Now I want test reports for all the 5 runs to be aggregated into one but it actually overwrites the previous report.

Is there any way to do that ?

Need help ASAP.

Thanks.

Now I want test reports for all the 5 runs to be aggregated into one but it actually overwrites the previous report.

Why do you want to run gradle 5 times?

Gradle has ability to execute tests on multi JVM processes, and their reports can be summarized.
Please check document on Test.

Test task has property maxParallelForks, which determines the number of processes to execute tests. If you set 5 to its value, tests can be executed in 5 parallel processes.

build.gradle

test {
    maxParallelForks = 5
}

Hi Shinya_Mochida,

Thanks for your prompt reply. But i t is my requirement to run gradle build multiple times so that each time it picks up a specfic test case based on my test scenario.

I see that in build–>reports–>tests folder there are individual test run html files but the index.html shows just the report for the last run test case and not the aggregate of all runs.

It would be great if there is any way to do it.

Thanks,
Nikhil

It seems this is not the problem of Gradle, but the problem of JUnit.

You should make your test suite class, for running test on your required order.

For example create test suite class.

@RunWith(Suite.class)
@SuiteClasses({
    FirstTest.class,
    SecondTest.class,
    ThirdTest.class
})
public class MyOrder {
}

And edit your build.gradle to use the suite class only.

test {
    include '**/*Order.class'
}

Then you can run with order as you wish, and reports can be referred by top index.html.