mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-25 16:07:12 -07:00
Extract TestNG results and show them in the final report.
This commit is contained in:
parent
ffd641310d
commit
a20b16da44
2 changed files with 38 additions and 2 deletions
|
@ -16,12 +16,14 @@ abstract class GenericTestRunner: ITestRunnerContributor {
|
||||||
abstract val mainClass: String
|
abstract val mainClass: String
|
||||||
abstract val annotationPackage: String
|
abstract val annotationPackage: String
|
||||||
abstract val runnerName: String
|
abstract val runnerName: String
|
||||||
open val shortMessage: String? = null//""Short message"
|
open var shortMessage: String? = null
|
||||||
open val longMessage: String? = null//""Long message"
|
open var longMessage: String? = null
|
||||||
|
|
||||||
abstract fun args(project: Project, context: KobaltContext, classpath: List<IClasspathDependency>,
|
abstract fun args(project: Project, context: KobaltContext, classpath: List<IClasspathDependency>,
|
||||||
testConfig: TestConfig) : List<String>
|
testConfig: TestConfig) : List<String>
|
||||||
|
|
||||||
|
open fun onFinish(project: Project) {}
|
||||||
|
|
||||||
open val extraClasspath: List<String> = emptyList()
|
open val extraClasspath: List<String> = emptyList()
|
||||||
|
|
||||||
open fun filterTestClasses(classes: List<String>) : List<String> = classes
|
open fun filterTestClasses(classes: List<String>) : List<String> = classes
|
||||||
|
@ -145,6 +147,7 @@ abstract class GenericTestRunner: ITestRunnerContributor {
|
||||||
throw KobaltException("Couldn't find a test configuration named \"$configName\"")
|
throw KobaltException("Couldn't find a test configuration named \"$configName\"")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onFinish(project)
|
||||||
return TestResult(result, shortMessage, longMessage)
|
return TestResult(result, shortMessage, longMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,8 +13,12 @@ import org.testng.remote.strprotocol.JsonMessageSender
|
||||||
import org.testng.remote.strprotocol.MessageHelper
|
import org.testng.remote.strprotocol.MessageHelper
|
||||||
import org.testng.remote.strprotocol.MessageHub
|
import org.testng.remote.strprotocol.MessageHub
|
||||||
import org.testng.remote.strprotocol.TestResultMessage
|
import org.testng.remote.strprotocol.TestResultMessage
|
||||||
|
import org.w3c.dom.Attr
|
||||||
|
import org.xml.sax.InputSource
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.io.FileReader
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
import javax.xml.parsers.DocumentBuilderFactory
|
||||||
|
|
||||||
class TestNgRunner : GenericTestRunner() {
|
class TestNgRunner : GenericTestRunner() {
|
||||||
|
|
||||||
|
@ -61,6 +65,35 @@ class TestNgRunner : GenericTestRunner() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract test results from testng-results.xml and initialize shortMessage.
|
||||||
|
*/
|
||||||
|
override fun onFinish(project: Project) {
|
||||||
|
File(defaultOutput(project), "testng-results.xml").let { file ->
|
||||||
|
val ins = InputSource(FileReader(file))
|
||||||
|
val doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(ins)
|
||||||
|
|
||||||
|
val root = doc.documentElement
|
||||||
|
var failed = 0
|
||||||
|
var skipped = 0
|
||||||
|
var passed = 0
|
||||||
|
repeat(root.attributes.length) {
|
||||||
|
val attribute = root.attributes.item(it)
|
||||||
|
if (attribute is Attr) when (attribute.name) {
|
||||||
|
"failed" -> failed = Integer.parseInt(attribute.value)
|
||||||
|
"skipped" -> skipped = Integer.parseInt(attribute.value)
|
||||||
|
"passed" -> passed = Integer.parseInt(attribute.value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (failed == 0) {
|
||||||
|
shortMessage = "$passed tests"
|
||||||
|
} else if (failed > 0) {
|
||||||
|
shortMessage = "$failed failed" + (if (skipped > 0) ", $skipped skipped" else "") + " tests"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val VERSION_6_10 = StringVersion("6.10")
|
val VERSION_6_10 = StringVersion("6.10")
|
||||||
|
|
||||||
fun _runTests(project: Project, context: KobaltContext, classpath: List<IClasspathDependency>,
|
fun _runTests(project: Project, context: KobaltContext, classpath: List<IClasspathDependency>,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue