I am new to CI & Jenkins. I have a Java project which runs Testng based automated tests. The tests run regularly as a job in Jenkins. Sometimes, the job fails repeatedly for
You can take the number of times a test failed from the build's object in a pipeline: you can make a small report and attach it to your build like so:
@NonCPS
def getRepeatedlyFailingTests(int timesFailedAtLeast = 2) {
currentBuild.rawBuild.getAction(hudson.tasks.junit.TestResultAction.class)
.getFailedTests()
// Keep only tests that failed at least twice
.findAll { it.age >= timesFailedAtLeast }
.collect { [ "${it.className}.${it.name}".trim(), it.age ] }
}
def saveRepeatedlyFailingTestsReport() {
def header = [ "test", "times-failed" ]
def records = getRepeatedlyFailingTests()
def report = "repeatedly-failing-tests.csv"
writeCSV file: report, records: [ header ] + records, format: CSVFormat.EXCEL
archiveArtifacts report
}
Call saveRepeatedlyFailingTestsReport
after you gather your test results and you'll see the report in your latest build artifacts link.
You can use the Test Result Analyzer plugin from Jenkins to analyse the trends of tests.
Test Result Analyzer plugin
Video Tutorial from youtube
Installation:
Usage:
**/target/test-results/*.xml
in my case