diff --git a/tools/intellij.lambda.testFramework/src/com/intellij/lambda/testFramework/junit/ExecuteInMonolithAndSplitMode.kt b/tools/intellij.lambda.testFramework/src/com/intellij/lambda/testFramework/junit/ExecuteInMonolithAndSplitMode.kt index 2104773c96d9..79f61d541516 100644 --- a/tools/intellij.lambda.testFramework/src/com/intellij/lambda/testFramework/junit/ExecuteInMonolithAndSplitMode.kt +++ b/tools/intellij.lambda.testFramework/src/com/intellij/lambda/testFramework/junit/ExecuteInMonolithAndSplitMode.kt @@ -24,4 +24,7 @@ enum class IdeRunMode { RemoteDevRun::class ) @TestInstance(TestInstance.Lifecycle.PER_CLASS) -annotation class ExecuteInMonolithAndSplitMode(vararg val mode: IdeRunMode = [IdeRunMode.MONOLITH, IdeRunMode.SPLIT]) \ No newline at end of file +annotation class ExecuteInMonolithAndSplitMode(vararg val mode: IdeRunMode = [IdeRunMode.MONOLITH, IdeRunMode.SPLIT]) + + +internal val isGroupedExecutionEnabled: Boolean = false \ No newline at end of file diff --git a/tools/intellij.lambda.testFramework/src/com/intellij/lambda/testFramework/junit/GroupByModePostDiscoveryFilter.kt b/tools/intellij.lambda.testFramework/src/com/intellij/lambda/testFramework/junit/GroupByModePostDiscoveryFilter.kt index d1abe7a45e6f..e1b2ac6834b2 100644 --- a/tools/intellij.lambda.testFramework/src/com/intellij/lambda/testFramework/junit/GroupByModePostDiscoveryFilter.kt +++ b/tools/intellij.lambda.testFramework/src/com/intellij/lambda/testFramework/junit/GroupByModePostDiscoveryFilter.kt @@ -1,9 +1,9 @@ package com.intellij.lambda.testFramework.junit import com.intellij.tools.ide.util.common.logOutput +import com.intellij.util.containers.orNull import org.junit.platform.engine.FilterResult import org.junit.platform.engine.TestDescriptor -import org.junit.platform.engine.support.descriptor.ClassSource import org.junit.platform.launcher.PostDiscoveryFilter /** @@ -17,46 +17,17 @@ class GroupByModePostDiscoveryFilter : PostDiscoveryFilter { } override fun apply(testDescriptor: TestDescriptor): FilterResult { - // Only filter Jupiter engine's tests - val engineId = testDescriptor.uniqueId.engineId.orElse(null) - if (engineId != "junit-jupiter") { - return FilterResult.included("Not a Jupiter test") + val engineId = testDescriptor.uniqueId.engineId.orNull() + + if (!isGroupedExecutionEnabled) { + log("Test descriptor is included in all JUnit engines because grouped execution is disabled") + return FilterResult.included("No filter is applied") } - // Check if this test belongs to a @GroupTestsByMode class - val source = testDescriptor.source.orElse(null) - if (source is ClassSource) { - try { - val clazz = Class.forName(source.className) - if (clazz.isAnnotationPresent(ExecuteInMonolithAndSplitMode::class.java)) { - log("Excluding ${source.className} from Jupiter") - return FilterResult.excluded("Managed by ${GroupByModeTestEngine::class.simpleName}") - } - } - catch (e: ClassNotFoundException) { - // Continue - } + if (engineId != GroupByModeTestEngine.ENGINE_ID) { + return FilterResult.excluded("Not a ${GroupByModeTestEngine.engineClassName} test") } - // Also check parent descriptors - var parent = testDescriptor.parent.orElse(null) - while (parent != null) { - val parentSource = parent.source.orElse(null) - if (parentSource is ClassSource) { - try { - val clazz = Class.forName(parentSource.className) - if (clazz.isAnnotationPresent(ExecuteInMonolithAndSplitMode::class.java)) { - log("Excluding ${testDescriptor.displayName} (parent has @${ExecuteInMonolithAndSplitMode::class.simpleName})") - return FilterResult.excluded("Parent managed by ${GroupByModeTestEngine::class.simpleName}") - } - } - catch (e: ClassNotFoundException) { - // Continue - } - } - parent = parent.parent.orElse(null) - } - - return FilterResult.included("Not a @${ExecuteInMonolithAndSplitMode::class.simpleName} test") + return FilterResult.included("Test is handled by ${GroupByModeTestEngine.engineClassName} engine") } } \ No newline at end of file diff --git a/tools/intellij.lambda.testFramework/src/com/intellij/lambda/testFramework/junit/GroupByModeTestEngine.kt b/tools/intellij.lambda.testFramework/src/com/intellij/lambda/testFramework/junit/GroupByModeTestEngine.kt index 38d98c749299..7e43f3289a45 100644 --- a/tools/intellij.lambda.testFramework/src/com/intellij/lambda/testFramework/junit/GroupByModeTestEngine.kt +++ b/tools/intellij.lambda.testFramework/src/com/intellij/lambda/testFramework/junit/GroupByModeTestEngine.kt @@ -19,10 +19,12 @@ import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder class GroupByModeTestEngine : TestEngine { companion object { const val ENGINE_ID = "group-by-mode" + val engineClassName = GroupByModeTestEngine::class.simpleName + private const val JUPITER_ENGINE_ID = "junit-jupiter" private val annotationName = ExecuteInMonolithAndSplitMode::class.simpleName - private val engineClassName = GroupByModeTestEngine::class.simpleName + private fun log(message: String) = logOutput("[$engineClassName]: $message") } @@ -35,6 +37,11 @@ class GroupByModeTestEngine : TestEngine { override fun getId(): String = ENGINE_ID override fun discover(discoveryRequest: EngineDiscoveryRequest, uniqueId: UniqueId): TestDescriptor { + if (!isGroupedExecutionEnabled) { + log("$engineClassName will not be used because grouped execution is disabled") + return GroupedModeEngineDescriptor(uniqueId, listOf(), discoveryRequest.configurationParameters) + } + log("Starting discovery with request: ${discoveryRequest.getSelectorsByType(ClassSelector::class.java).map { it.className }}") // Filter to only get classes with @ExecuteInMonolithAndSplitMode