Execute integration test task multiple times internally


(kikimoreva) #1

Hey,

I am trying to run gradle integration test task multiple times and set a java system property used by the test classes to a different value each time.
My goal is to run all tests part of a particular category, while setting all categories as default.

Unfortunately, this is not working. Looks like the tests are executed only with the last listed category.
I tried making ‘singleCategory’ an external property but this did not help.

Any idea how to do this so that it works?

Here is how the task looks:

String categories = "${project.findProperty(‘requiredCategory’) ?: “com.pcbsys.nirvana.junit.categories.TestClassifier.PromotionIntegrationTest,com.pcbsys.nirvana.junit.categories.TestClassifier.PromotionSystemTest,com.pcbsys.nirvana.junit.categories.TestClassifier.PromotionUnitTest,com.pcbsys.nirvana.junit.categories.TestClassifier.PromotionPerformanceTest”}"
String suite = "${project.findProperty(‘requiredSuite’) ?: ‘com/pcbsys/foundation/suites/PromotionTests.class’}"
integrationTest {

String[] allCategories = categories.split(",");
String singleCategory;
for (int i = 0; i < allCategories.length; i++) {
	singleCategory = allCategories[i];
	System.out.println("**********************Running: $suite with category: $singleCategory**********************");
		useJUnit {	
		include suite
		systemProperties = [	
			//'EXCEPTION_INSTRUMENT_AGENT' 		:	exceptionInstrumentJarPath,
			'LOGLEVEL'							: 	System.getProperty ("logLevel", "1"),
			'EnableDebug'						: 	System.getProperty ("debugFlag", "none"),
			'LICENCE_DIR'						: 	basedir + "/build/builds/nirvana/launchers/server",
			'LICENCE_FILE'						: 	"licence.xml",
			'JUnitBasePort'						: 	junitBasePort,
			'nirvana.test.requiredCategories'	: 	singleCategory
		]
	}
}

String[] categoryParticles = singleCategory.split("\\.");
String reportName = categoryParticles[6];
def reportsDirectory = "$projectDir/$reportName"

reports { 
    html.destination = reportsDirectory
    junitXml.destination = reportsDirectory
}

}

String[] categoryParticles = singleCategory.split("\\.");
String reportName = categoryParticles[6];
def reportsDirectory = "$projectDir/$reportName"

reports { 
    html.destination = reportsDirectory
    junitXml.destination = reportsDirectory
}

}


(kikimoreva) #2

It looks like what I wanted to do is not possible. The proper way to do it is to create a dynamic task for each category. Here is how I did it and it works:

def categories = [ “com.pcbsys.nirvana.junit.categories.TestClassifier.PromotionUnitTest”, “com.pcbsys.nirvana.junit.categories.TestClassifier.PromotionIntegrationTest”, “com.pcbsys.nirvana.junit.categories.TestClassifier.PromotionSystemTest”, “com.pcbsys.nirvana.junit.categories.TestClassifier.PromotionPerformanceTest” ];

task runAllTests (type: Test, description: “Runs all tests under $project.name project”) {
}
runAllTests.dependsOn {
tasks.findAll { task -> task.name.contains(‘TestClassifier’) }
}

integrationTest.dependsOn {
tasks.findAll { task -> task.name.contains(‘TestClassifier’) }
}

categories.each { it ->
String singleCategory = "${it}"
task “${it}” (type: Test, dependsOn: ‘integTestClasses’, description: “Runs tests by category in a given suite”) {
println "Created dynamic task: $singleCategory"
testClassesDir = sourceSets.integTest.output.classesDir
classpath = project.sourceSets.integTest.runtimeClasspath
useJUnit()
include suite
systemProperties = [
‘LOGLEVEL’ : System.getProperty (“logLevel”, “1”),
‘EnableDebug’ : System.getProperty (“debugFlag”, “none”),
‘LICENCE_DIR’ : basedir + “/build/builds/nirvana/launchers/server”,
‘LICENCE_FILE’ : “licence.xml”,
‘JUnitBasePort’ : junitBasePort,
‘nirvana.test.requiredCategories’ : singleCategory
]

	String[] categoryParticles = "$singleCategory".split("\\.");
	String reportName = categoryParticles[6];
	def reportsDirectory = "$projectDir/$reportName"
	
	reports { 
		html.destination = reportsDirectory
		junitXml.destination = reportsDirectory
	}
}

}