mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
TestNG runner work in progress.
This commit is contained in:
parent
3ee309fa37
commit
a3734f88c3
2 changed files with 84 additions and 1 deletions
|
@ -94,7 +94,7 @@ abstract class GenericTestRunner: ITestRunnerContributor {
|
||||||
/**
|
/**
|
||||||
* @return true if all the tests passed
|
* @return true if all the tests passed
|
||||||
*/
|
*/
|
||||||
fun runTests(project: Project, context: KobaltContext, classpath: List<IClasspathDependency>,
|
open fun runTests(project: Project, context: KobaltContext, classpath: List<IClasspathDependency>,
|
||||||
configName: String) : Boolean {
|
configName: String) : Boolean {
|
||||||
var result = false
|
var result = false
|
||||||
|
|
||||||
|
|
|
@ -4,9 +4,17 @@ import com.beust.kobalt.TestConfig
|
||||||
import com.beust.kobalt.api.IClasspathDependency
|
import com.beust.kobalt.api.IClasspathDependency
|
||||||
import com.beust.kobalt.api.KobaltContext
|
import com.beust.kobalt.api.KobaltContext
|
||||||
import com.beust.kobalt.api.Project
|
import com.beust.kobalt.api.Project
|
||||||
|
import com.beust.kobalt.homeDir
|
||||||
import com.beust.kobalt.misc.KFiles
|
import com.beust.kobalt.misc.KFiles
|
||||||
|
import com.beust.kobalt.misc.runCommand
|
||||||
import com.beust.kobalt.misc.warn
|
import com.beust.kobalt.misc.warn
|
||||||
|
import org.testng.remote.RemoteArgs
|
||||||
|
import org.testng.remote.strprotocol.JsonMessageSender
|
||||||
|
import org.testng.remote.strprotocol.MessageHelper
|
||||||
|
import org.testng.remote.strprotocol.MessageHub
|
||||||
|
import org.testng.remote.strprotocol.TestResultMessage
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.io.IOException
|
||||||
|
|
||||||
class TestNgRunner : GenericTestRunner() {
|
class TestNgRunner : GenericTestRunner() {
|
||||||
|
|
||||||
|
@ -48,4 +56,79 @@ class TestNgRunner : GenericTestRunner() {
|
||||||
addAll(testConfig.testArgs)
|
addAll(testConfig.testArgs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun _runTests(project: Project, context: KobaltContext, classpath: List<IClasspathDependency>,
|
||||||
|
configName: String): Boolean {
|
||||||
|
var result = false
|
||||||
|
val port = 2345
|
||||||
|
|
||||||
|
val classpath = listOf(homeDir("java/jcommander/kobaltBuild/classes"),
|
||||||
|
homeDir(".kobalt/cache/org/testng/testng/6.10/testng-6.10.jar"),
|
||||||
|
homeDir(".kobalt/cache/com/beust/jcommander/1.66/jcommander-1.66.jar"),
|
||||||
|
homeDir(".kobalt/cache/org/yaml/snakeyaml/1.17/snakeyaml-1.17.jar"),
|
||||||
|
homeDir(".kobalt/cache/com/google/code/findbugs/jsr305/3.0.1/jsr305-3.0.1.jar"),
|
||||||
|
homeDir("java/jcommander/kobaltBuild/test-classes"),
|
||||||
|
homeDir("java/jcommander/src/test/resources/testng.xml"),
|
||||||
|
homeDir("kotlin/kobalt/lib/testng-remote-1.3.0-SNAPSHOT.jar"),
|
||||||
|
homeDir("kotlin/kobalt/lib/testng-remote6_10-1.3.0-SNAPSHOT.jar")
|
||||||
|
).joinToString(File.pathSeparator)
|
||||||
|
val passedArgs = listOf(
|
||||||
|
"-classpath",
|
||||||
|
classpath,
|
||||||
|
"org.testng.remote.RemoteTestNG",
|
||||||
|
"-serport", port.toString(),
|
||||||
|
"-version", "6.10",
|
||||||
|
"-dontexit",
|
||||||
|
RemoteArgs.PROTOCOL,
|
||||||
|
"json",
|
||||||
|
"src/test/resources/testng.xml")
|
||||||
|
|
||||||
|
Thread {
|
||||||
|
val exitCode = runCommand {
|
||||||
|
command = "java"
|
||||||
|
directory = File(homeDir("java/jcommander"))
|
||||||
|
args = passedArgs
|
||||||
|
}
|
||||||
|
}.start()
|
||||||
|
|
||||||
|
// Thread {
|
||||||
|
// val args2 = arrayOf("-serport", port.toString(), "-dontexit", RemoteArgs.PROTOCOL, "json",
|
||||||
|
// "-version", "6.10",
|
||||||
|
// "src/test/resources/testng.xml")
|
||||||
|
// RemoteTestNG.main(args2)
|
||||||
|
// }.start()
|
||||||
|
|
||||||
|
val mh = MessageHub(JsonMessageSender("localhost", port, true))
|
||||||
|
mh.setDebug(true)
|
||||||
|
mh.initReceiver()
|
||||||
|
val passed = arrayListOf<String>()
|
||||||
|
data class FailedTest(val method: String, val cls: String, val stackTrace: String)
|
||||||
|
val failed = arrayListOf<FailedTest>()
|
||||||
|
var skipped = arrayListOf<String>()
|
||||||
|
try {
|
||||||
|
var message = mh.receiveMessage()
|
||||||
|
println("")
|
||||||
|
while (message != null) {
|
||||||
|
message = mh.receiveMessage()
|
||||||
|
if (message is TestResultMessage) {
|
||||||
|
when(message.result) {
|
||||||
|
MessageHelper.PASSED_TEST -> passed.add(message.name)
|
||||||
|
MessageHelper.FAILED_TEST -> failed.add(FailedTest(message.testClass,
|
||||||
|
message.method, message.stackTrace))
|
||||||
|
MessageHelper.SKIPPED_TEST -> skipped.add(message.name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
print("\r" + String.format("%4d / %4d / %4d", passed.size, failed.size, skipped.size))
|
||||||
|
// Thread.sleep(200)
|
||||||
|
}
|
||||||
|
} catch(ex: IOException) {
|
||||||
|
println("Exception: ${ex.message}")
|
||||||
|
}
|
||||||
|
println("\nPassed: " + passed.size + ", Failed: " + failed.size + ", Skipped: " + skipped.size)
|
||||||
|
failed.forEach {
|
||||||
|
val top = it.stackTrace.substring(0, it.stackTrace.indexOf("\n"))
|
||||||
|
println(" " + it.cls + "." + it.method + "\n " + top)
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue