Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run a specific TestNG XML test suite with Gradle from command line?

Tags:

gradle

testng

I am using Gradle with TestNG. I have this build.gradle:

useTestNG() {
        useDefaultListeners = true
        suites "src/test/resources/tests1.xml"
        suites "src/test/resources/tests2.xml"
   }
}

How can I run for example only tests1.xml from command line?

like image 381
Gudzo Avatar asked Jan 05 '23 03:01

Gudzo


2 Answers

you can use project properties to add/change/... different suites. In you example you are probably running

gradlew test

which run both suites. If you modify test task in your build.gradle

def suite1 = project.hasProperty("suite1")
def suite2 = project.hasProperty("suite2")

test {
    useTestNG() {
        dependsOn cleanTest
        useDefaultListeners = true

        if(suite1) {
            suites "src/test/resources/simpleSuite.xml"
        }

        if(suite2) {
            suites "src/test/resources/advancedSuite.xml"
        }
    }
}

you can choose suite in this way

gradlew test -Psuite1
gradlew test -Psuite2
gradlew test -Psuite1 -Psuite2
like image 152
Jaroslav Cincera Avatar answered Apr 30 '23 03:04

Jaroslav Cincera


you can specify variable let say suiteFile with default value and use it in testNG section. For example:

ext{

    set suiteFile, default is 'testrun_config.xml'
    if (!project.hasProperty('suiteFile')) {
        suiteFile = 'testrun_config.xml'
    }
}

test {
    useTestNG() {
        dependsOn cleanTest
        useDefaultListeners = true
        suites "src/test/resources/"+suiteFile

    }
} 

Refer qaf gradle build file

If you want to pass through command line

gradlew test -PsuiteFile=test.xml
like image 43
user861594 Avatar answered Apr 30 '23 04:04

user861594