From 1efd583e1492fcb48d2c79cb452efc8a3c729d93 Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Wed, 1 Dec 2021 18:48:21 +0300 Subject: [PATCH] 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 --- buildSrc/src/main/kotlin/tasks.kt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/buildSrc/src/main/kotlin/tasks.kt b/buildSrc/src/main/kotlin/tasks.kt index 8ba17d1ed3d..3c8846cbd85 100644 --- a/buildSrc/src/main/kotlin/tasks.kt +++ b/buildSrc/src/main/kotlin/tasks.kt @@ -110,6 +110,8 @@ fun Project.projectTest( } return getOrCreateTask(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") } } }