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

Simplify test runners.

This commit is contained in:
Cedric Beust 2015-12-16 18:35:53 +04:00
parent fd19860493
commit 4fd276cc89
3 changed files with 8 additions and 17 deletions

View file

@ -3,10 +3,7 @@ package com.beust.kobalt.internal
import com.beust.kobalt.JavaInfo
import com.beust.kobalt.SystemProperties
import com.beust.kobalt.TaskResult
import com.beust.kobalt.api.IClasspathDependency
import com.beust.kobalt.api.ITestRunnerContributor
import com.beust.kobalt.api.KobaltContext
import com.beust.kobalt.api.Project
import com.beust.kobalt.api.*
import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.log
import java.io.File
@ -14,15 +11,19 @@ import java.net.URLClassLoader
/**
* Base class for testing frameworks that are invoked from a main class with arguments. Test runners can
* subclass this class and override mainClass and args.
* subclass this class and override mainClass, args and the name of the dependency that should trigger this runner.
*/
abstract class GenericTestRunner : ITestRunnerContributor {
abstract val dependencyName : String
abstract val mainClass: String
abstract fun args(project: Project, classpath: List<IClasspathDependency>) : List<String>
override fun run(project: Project, context: KobaltContext, classpath: List<IClasspathDependency>)
= TaskResult(runTests(project, classpath))
override fun affinity(project: Project, context: KobaltContext) =
if (project.testDependencies.any { it.id.contains(dependencyName)}) IAffinity.DEFAULT_POSITIVE_AFFINITY
else 0
protected fun findTestClasses(project: Project, classpath: List<IClasspathDependency>): List<String> {
val path = KFiles.joinDir(project.directory, project.buildDirectory, KFiles.TEST_CLASSES_DIR)

View file

@ -1,19 +1,13 @@
package com.beust.kobalt.internal
import com.beust.kobalt.api.IAffinity
import com.beust.kobalt.api.IClasspathDependency
import com.beust.kobalt.api.KobaltContext
import com.beust.kobalt.api.Project
open public class JUnitRunner() : GenericTestRunner() {
override val mainClass = "org.junit.runner.JUnitCore"
open val dependencyName = "junit"
override fun affinity(project: Project, context: KobaltContext) =
if (project.testDependencies.any { it.id.contains(dependencyName)}) IAffinity.DEFAULT_POSITIVE_AFFINITY
else 0
override val dependencyName = "junit"
override fun args(project: Project, classpath: List<IClasspathDependency>) = findTestClasses(project, classpath)
}

View file

@ -1,8 +1,6 @@
package com.beust.kobalt.internal
import com.beust.kobalt.api.IAffinity
import com.beust.kobalt.api.IClasspathDependency
import com.beust.kobalt.api.KobaltContext
import com.beust.kobalt.api.Project
import com.beust.kobalt.misc.KFiles
import java.io.File
@ -11,9 +9,7 @@ public class TestNgRunner() : GenericTestRunner() {
override val mainClass = "org.testng.TestNG"
override fun affinity(project: Project, context: KobaltContext) =
if (project.testDependencies.any { it.id.contains("testng")}) IAffinity.DEFAULT_POSITIVE_AFFINITY
else 0
override val dependencyName = "org.testng"
override fun args(project: Project, classpath: List<IClasspathDependency>) = arrayListOf<String>().apply {
if (project.testArgs.size > 0) {