mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-25 07:57:12 -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:
parent
104e71335e
commit
5d03544e31
3 changed files with 21 additions and 3 deletions
|
@ -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 })
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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) }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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("$") }
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue