I have a gradle task that collects a bunch of tests in a filetree and then uses ant.junit to run them
includedTests = fileTree(dir: "${targetDir}",
include: ["**/*Test*.class"],
exclude: [ "**/TestNotToBeRun.class"])
includedTests = includedTests.collect { it }
ant.junit(...) {
...
....
batchtest(todir: "${testDir}") {
ant.filelist(dir: "${targetDir}", files: includedTests.join(","))
}
}
I want to run these tests in separate jvms and the number will be provided as a property say 4. I wanted to do this by using forkmode: “perBatch”. Hence I am trying to divide the Batch into 4 parts. Is there a way I can divide the filetree into 4 parts? Or can I divide the ant filelist into 4 parts?
I was thinking of doing something like this post: https://stackoverflow.com/questions/2373589/how-to-split-an-fileset-in-ant-into-multiple-sets
def filelist = ant.filelist(dir: "${targetTestDir}/build", files: includedTests.join(","))
def batchSize = (includedTests.length/4) + 1;
def batch = 1;
for (def i = 0; i < includedTests.length; i += batchSize)
{
// Create a new fileset to hold the sub-Fileset.
def filelistN = project.createDataType( "filelist" );
filelistN.setDir(filelist.getDir());
// Give the new Fileset an id and associate with the project.
project.addReference( "Filelist" + batch, filelistN );
// Populate the sub-Fileset.
for (def j = 0; j < batchSize && ( i + j ) < includedTests.length; j++ )
{
filelistN.setIncludes( includedTests[i + j] );
}
batch++;
}
//Not sure this is possible. Or what the correct format would be for the following
batchtest(todir: "${testDir}") {
filelist1
}