We know how to execute the whole set of test suite using gradle, here in this blog we show you how do we call specific set of tests with gradle which we have segregated tests based on multiple testng.xml files?
Solution: Add below snippet at end of build.gradle file, we will define suites with project property function, and we will pass these suite objects to useTestNG function by validating user defined suite name with passed suite object.
=====================================
def suite1=project.hasProperty("suite1")
def suite2=project.hasProperty("suite2")
def suite3=project.hasProperty("suite3")
test {
testLogging {
exceptionFormat = 'full'
events = ["passed", "failed", "skipped"]
showStandardStreams = true
}
useTestNG() {
/*This XML file is to execute first test suite*/
if(project.hasProperty("suite1")) {
suites "testng1.xml"
}
/*This XML file is to execute second test suite*/
if(project.hasProperty("suite2")) {
suites "testng2.xml"
}
/*This XML file is to execute third test suite*/
if(project.hasProperty("suite3")) {
suites "testng3.xml"
}
}
=======================================
When we run "gradle test -Psuite1" in command line of repo, which will only execute all the tests defined in testng1.xml file, use same for suite2(gradle test -Psuite2) and suite3(gradle test -Psuite3) and so on.
Comments
Post a Comment