seleniumjenkinsjenkins-pipelinetestngslack

Jenkins - Display names of failed tests TestNG


In my Jenkinsfile i'm counting all test results as

AbstractTestResultAction testResultAction = currentBuild.rawBuild.getAction(AbstractTestResultAction.class)
    if (testResultAction != null) {
        def total = testResultAction.totalCount
        def failed = testResultAction.failCount
        def skipped = testResultAction.skipCount
        def passed = total - failed - skipped

But I also want to display all names of failed tests for slack message. So far, i've tried to generate it with def failedTests = testResultAction.getResult().getFailedTests() but it returns not specific name like hudson.tasks.junit.CaseResult@37e0fb97. Is there anyway to display full name of test? I am using Selenium + TestNG.


Solution

  • You can get description using .getTitle() method:

    def failedTests = testResultAction.getResult().getFailedTests().collect { it.getTitle() }