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

GH-417: Don’t run abstract test classes with JUnit 4.

Fixes https://github.com/cbeust/kobalt/issues/417
This commit is contained in:
Cedric Beust 2017-04-18 20:01:43 -07:00
parent 104e71335e
commit 5d03544e31
3 changed files with 21 additions and 3 deletions

View file

@ -30,7 +30,7 @@ abstract class GenericTestRunner: ITestRunnerContributor {
open val extraClasspath: List<String> = emptyList()
open fun filterTestClasses(classes: List<String>) : List<String> = classes
open fun filterTestClasses(project: Project, context: KobaltContext, classes: List<String>) : List<String> = classes
override fun run(project: Project, context: KobaltContext, configName: String,
classpath: List<IClasspathDependency>) : TaskResult {
@ -69,7 +69,7 @@ abstract class GenericTestRunner: ITestRunnerContributor {
// }
context.logger.log(project.name, 2, "Found ${result.size} test classes")
return filterTestClasses(result.map { it.second })
return filterTestClasses(project, context, result.map { it.second })
}
/**

View file

@ -4,6 +4,10 @@ import com.beust.kobalt.TestConfig
import com.beust.kobalt.api.IClasspathDependency
import com.beust.kobalt.api.KobaltContext
import com.beust.kobalt.api.Project
import com.beust.kobalt.maven.DependencyManager
import com.google.inject.Inject
import java.lang.reflect.Modifier
import java.net.URLClassLoader
open class JUnitRunner() : GenericTestRunner() {
@ -14,5 +18,15 @@ open class JUnitRunner() : GenericTestRunner() {
override fun args(project: Project, context: KobaltContext, classpath: List<IClasspathDependency>,
testConfig: TestConfig) = findTestClasses(project, context, testConfig)
@Inject
lateinit var dependencyManager: DependencyManager
override fun filterTestClasses(project: Project, context: KobaltContext, classes: List<String>) : List<String> {
val deps = dependencyManager.testDependencies(project, context)
val cl = URLClassLoader(deps.map { it.jarFile.get().toURI().toURL() }.toTypedArray())
return classes.filter { !Modifier.isAbstract(cl.loadClass(it).modifiers) }
}
}

View file

@ -1,5 +1,8 @@
package com.beust.kobalt.internal
import com.beust.kobalt.api.KobaltContext
import com.beust.kobalt.api.Project
/**
* KotlinTestRunner triggers if it finds a dependency on io.kotlintest but other than that, it just
* uses the regular JUnitRunner.
@ -12,6 +15,7 @@ class KotlinTestRunner : JUnitRunner() {
* KotlinTestRunner runs tests in the init{} initializer, so ignore all the extra
* classes generated by the Kotlin compiler.
*/
override fun filterTestClasses(classes: List<String>) = classes.filter { ! it.contains("$") }
override fun filterTestClasses(projet: Project, context: KobaltContext, classes: List<String>)
= classes.filter { !it.contains("$") }
}