Jenkins - 显示失败测试的名称 TestNG

Jenkins - Display names of failed tests TestNG

在我的 Jenkinsfile 中,我将所有测试结果计算为

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

但我还想显示松弛消息的所有失败测试的名称。 到目前为止,我已经尝试用 def failedTests = testResultAction.getResult().getFailedTests() 生成它,但它 returns 不是像 hudson.tasks.junit.CaseResult@37e0fb97 这样的特定名称。 无论如何要显示测试的全名?我正在使用 Selenium + TestNG。

您可以使用.getTitle()方法获取描述:

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