From a6097dc1368bcecb8bb7ce90c67a17da48c676ad Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Sat, 10 Nov 2018 08:11:08 -0800 Subject: [PATCH] Better test results. --- .../com/beust/kobalt/internal/GenericRunner.kt | 15 +++++++++------ .../com/beust/kobalt/internal/TestNgRunner.kt | 13 +++++++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/GenericRunner.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/GenericRunner.kt index e262cf93..995dba53 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/GenericRunner.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/GenericRunner.kt @@ -116,6 +116,7 @@ abstract class GenericTestRunner: ITestRunnerContributor { val testConfig = project.testConfigs.firstOrNull { it.name == configName } + var errorCode = -1 if (testConfig != null) { val args = args(project, context, classpath, testConfig) if (args.size > 0) { @@ -136,12 +137,7 @@ abstract class GenericTestRunner: ITestRunnerContributor { context.logger.log(project.name, 2, "Running tests with classpath size ${classpath.size}") context.logger.log(project.name, 2, "Launching " + allArgs.joinToString(" ")) val process = pb.start() - val errorCode = process.waitFor() - if (errorCode == 0) { - context.logger.log(project.name, 1, "All tests passed") - } else { - context.logger.log(project.name, 1, "Test failures") - } + errorCode = process.waitFor() result = result || errorCode == 0 } else { context.logger.log(project.name, 1, " No tests to run") @@ -152,6 +148,13 @@ abstract class GenericTestRunner: ITestRunnerContributor { } onFinish(project) + + if (errorCode == 0) { + context.logger.log(project.name, 1, "All tests passed") + } else { + context.logger.log(project.name, 1, longMessage!!) + } + return TestResult(result, shortMessage, longMessage) } diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt index b56a4aeb..f4ee96f8 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt @@ -14,11 +14,14 @@ import org.testng.remote.strprotocol.MessageHelper import org.testng.remote.strprotocol.MessageHub import org.testng.remote.strprotocol.TestResultMessage import org.w3c.dom.Attr +import org.w3c.dom.NodeList import org.xml.sax.InputSource import java.io.File import java.io.FileReader import java.io.IOException import javax.xml.parsers.DocumentBuilderFactory +import javax.xml.xpath.XPathConstants +import javax.xml.xpath.XPathFactory class TestNgRunner : GenericTestRunner() { @@ -82,6 +85,15 @@ class TestNgRunner : GenericTestRunner() { var failed = 0 var skipped = 0 var passed = 0 + val xp = XPathFactory.newInstance().newXPath() + val testMethods = xp.compile("/testng-results/suite/test/class/test-method[@status='FAIL']") + .evaluate(doc, XPathConstants.NODESET) + as NodeList + val failedMethods = arrayListOf() + repeat(testMethods.length) { + val tm = testMethods.item(it) + failedMethods.add(tm.attributes.getNamedItem("signature").textContent) + } repeat(root.attributes.length) { val attribute = root.attributes.item(it) if (attribute is Attr) when (attribute.name) { @@ -95,6 +107,7 @@ class TestNgRunner : GenericTestRunner() { shortMessage = "$passed tests" } else if (failed > 0) { shortMessage = "$failed failed" + (if (skipped > 0) ", $skipped skipped" else "") + " tests" + longMessage = "Failed tests:\n " + failedMethods.joinToString("\n ") } } }