[Build] Fix gradle tests filter for JUnit 5
There is an a optimization in our `projectTest` config which filters out some compiled test classes if they didn't contain specified test (if user ran :test task with --tests flag). This optimization for one tests left only one .class file which contains test. But JUnit 5 for tests in inner classes (with @Nested annotation) requires not only target class, but and all it's containers Test: package.SomeTest$Nested.testMethod JUnit4: package/SomeTest$Nested.class JUnit5: - package/SomeTest.class - package/SomeTest$Nested.class
This commit is contained in:
@@ -76,6 +76,7 @@ fun Project.projectTest(
|
|||||||
taskName: String = "test",
|
taskName: String = "test",
|
||||||
parallel: Boolean = false,
|
parallel: Boolean = false,
|
||||||
shortenTempRootName: Boolean = false,
|
shortenTempRootName: Boolean = false,
|
||||||
|
jUnit5Enabled: Boolean = false,
|
||||||
body: Test.() -> Unit = {}
|
body: Test.() -> Unit = {}
|
||||||
): TaskProvider<Test> = getOrCreateTask(taskName) {
|
): TaskProvider<Test> = getOrCreateTask(taskName) {
|
||||||
doFirst {
|
doFirst {
|
||||||
@@ -109,12 +110,29 @@ fun Project.projectTest(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
include {
|
val parentNames = if (jUnit5Enabled) {
|
||||||
val path = it.path
|
/*
|
||||||
if (it.isDirectory) {
|
* If we run test from inner test class with junit 5 we need
|
||||||
|
* to include all containing classes of our class
|
||||||
|
*/
|
||||||
|
val nestedNames = classFileNameWithoutExtension.split("$")
|
||||||
|
mutableListOf(nestedNames.first()).also {
|
||||||
|
for (s in nestedNames.subList(1, nestedNames.size)) {
|
||||||
|
it += "${it.last()}\$$s"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else emptyList()
|
||||||
|
|
||||||
|
include { treeElement ->
|
||||||
|
val path = treeElement.path
|
||||||
|
if (treeElement.isDirectory) {
|
||||||
classFileNameWithoutExtension.startsWith(path)
|
classFileNameWithoutExtension.startsWith(path)
|
||||||
} else {
|
} else {
|
||||||
path == classFileName || (path.endsWith(".class") && path.startsWith("$classFileNameWithoutExtension$"))
|
if (jUnit5Enabled) {
|
||||||
|
path == classFileName || (path.endsWith(".class") && parentNames.any { path.startsWith(it) })
|
||||||
|
} else {
|
||||||
|
path == classFileName || (path.endsWith(".class") && path.startsWith("$classFileNameWithoutExtension$"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ if (kotlinBuildProperties.isInJpsBuildIdeaSync) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
projectTest(parallel = true) {
|
projectTest(parallel = true, jUnit5Enabled = true) {
|
||||||
dependsOn(":dist")
|
dependsOn(":dist")
|
||||||
workingDir = rootDir
|
workingDir = rootDir
|
||||||
jvmArgs!!.removeIf { it.contains("-Xmx") }
|
jvmArgs!!.removeIf { it.contains("-Xmx") }
|
||||||
|
|||||||
Reference in New Issue
Block a user