Fix running nested classes with JUnit 5 causes outer class tests execution
Note: there might be a performance issue with running tests, the reason why custom filtering was added to the tests running. It's not tested and should be addressed separately Try run IrBlackBoxCodegenTestGenerated.Annotations. Everything in the outer class IrBlackBoxCodegenTestGenerated is run instead. This is not an IDEA problem, since it reproduces from the command line too. ^KTI-712 Fixed
This commit is contained in:
@@ -110,6 +110,8 @@ fun Project.projectTest(
|
||||
}
|
||||
return getOrCreateTask<Test>(taskName) {
|
||||
doFirst {
|
||||
if (jUnitMode == JUnitMode.JUnit5) return@doFirst
|
||||
|
||||
val commandLineIncludePatterns = (filter as? DefaultTestFilter)?.commandLineIncludePatterns?.toMutableList() ?: mutableSetOf()
|
||||
val patterns = filter.includePatterns + commandLineIncludePatterns
|
||||
if (patterns.isEmpty() || patterns.any { '*' in it }) return@doFirst
|
||||
@@ -143,7 +145,7 @@ fun Project.projectTest(
|
||||
val parentNames = if (jUnitMode != JUnitMode.JUnit4) {
|
||||
/*
|
||||
* If we run test from inner test class with junit 5 we need
|
||||
* to include all containing classes of our class
|
||||
* to include all containing classes of our class
|
||||
*/
|
||||
val nestedNames = classFileNameWithoutExtension.split("$")
|
||||
mutableListOf(nestedNames.first()).also {
|
||||
@@ -160,10 +162,10 @@ fun Project.projectTest(
|
||||
} else {
|
||||
if (path == classFileName) return@include true
|
||||
if (!path.endsWith(".class")) return@include false
|
||||
when(jUnitMode) {
|
||||
JUnitMode.JUnit5 -> parentNames.any { path.startsWith(it) }
|
||||
when (jUnitMode) {
|
||||
JUnitMode.JUnit4 -> path.startsWith("$classFileNameWithoutExtension$")
|
||||
JUnitMode.Mix -> parentNames.any { path.startsWith(it) } || path.startsWith("$classFileNameWithoutExtension$")
|
||||
else -> error("JUnit5 should not be reachable because of early exit")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user