diff --git a/src/main/kotlin/com/beust/kobalt/internal/GenericRunner.kt b/src/main/kotlin/com/beust/kobalt/internal/GenericRunner.kt index f6b44b14..e7b4756b 100644 --- a/src/main/kotlin/com/beust/kobalt/internal/GenericRunner.kt +++ b/src/main/kotlin/com/beust/kobalt/internal/GenericRunner.kt @@ -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) : List override fun run(project: Project, context: KobaltContext, classpath: List) = 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): List { val path = KFiles.joinDir(project.directory, project.buildDirectory, KFiles.TEST_CLASSES_DIR) diff --git a/src/main/kotlin/com/beust/kobalt/internal/JUnitRunner.kt b/src/main/kotlin/com/beust/kobalt/internal/JUnitRunner.kt index 5d0cb604..64350134 100644 --- a/src/main/kotlin/com/beust/kobalt/internal/JUnitRunner.kt +++ b/src/main/kotlin/com/beust/kobalt/internal/JUnitRunner.kt @@ -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) = findTestClasses(project, classpath) } diff --git a/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt b/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt index 5254420a..fb2e0dba 100644 --- a/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt +++ b/src/main/kotlin/com/beust/kobalt/internal/TestNgRunner.kt @@ -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) = arrayListOf().apply { if (project.testArgs.size > 0) {