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

后端 未结 3 1833
-上瘾入骨i
-上瘾入骨i 2021-02-11 03:03

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

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


        
3条回答
  •  梦谈多话
    2021-02-11 03:54

    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
    

提交回复
热议问题