How to Run TestNG Tests on Jenkins

后端 未结 3 1006
傲寒
傲寒 2020-11-30 13:00

I\'m trying to run TestNG tests (in a contained Java project) from Jenkins but having no luck.

It appears as though the TestNG plugin for Jenkins (https://wiki.jen

3条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-30 13:07

    I use gradle to run my testNG tests from Jenkins. Take a look at the gradle docs.

    I run the testNG tests using configuration xml files. Take a look at the testNG docs.

    There is quite a lot to cover so I suggest reading these sources but I'll provide some relevant pieces from one of my configurations.

    The relevant parts from my build.gradle

    tasks.withType(Test) {
    
        useTestNG {
            useDefaultListeners = true
        }
    
        options {
            outputDirectory = file('test-report')
            listeners << 'org.uncommons.reportng.JUnitXMLReporter'
        }
    
        testLogging.showStandardStreams = true
    
        systemProperties System.getProperties()
        systemProperty "org.uncommons.reportng.escape-output", "false"
        systemProperty "org.uncommons.reportng.title", "Test Report"
    
        ignoreFailures = true
    }
    
    
    task Smoke_Test(type: Test) {
        description "SmokeTest"
        options.suites("resources/testng-smoketest.xml")      
        ignoreFailures = false
    }
    

    My testNG xml as referenced above 'testng-smoketest.xml'

    
    
    
        
            
                
            
        
        
    

    And from Jenkins, as an 'execute shell' build step run the gradle task, I use gradle wrapper for convenience.

    ./gradlew clean Smoke_Test
    

    Ensure you're in the correct directory, 'Smoke_Test' is the name specified in the build.gradle.

    You can use the testNG Jenkins plugin for saving your results.

    I also recommend using reportng for nice formatting of your test reports which can also be shown and saved in Jenkins using the HTML Publisher plugin.

    Try getting this to run from a CLI on your local machine first, trying to debug when running from Jenkins will drive you crazy.

提交回复
热议问题