1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-25 07:57:12 -07:00

Better test results.

This commit is contained in:
Cedric Beust 2018-11-10 08:11:08 -08:00
parent e22b5b77e6
commit a6097dc136
2 changed files with 22 additions and 6 deletions

View file

@ -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)
}

View file

@ -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<String>()
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 ")
}
}
}