From e45c2d31bcfba289b3c0a3e8667a841827e68e34 Mon Sep 17 00:00:00 2001 From: Ilya Matveev Date: Wed, 3 Feb 2021 13:29:46 +0700 Subject: [PATCH] [kotlin.test] Do not run test suites containing only ignored tests Popular frameworks such as JUnit, TestNG and Google Test do not run @BeforeClass/@AfterClass hooks of test suites containing only ignored tests. This patch introduces the same behaviour to the Kotlin/Native's kotlin.test runner. See also: #4522, #4615. --- kotlin-native/backend.native/tests/build.gradle | 5 ++--- .../kotlin/kotlin/native/internal/test/TestRunner.kt | 9 +++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/kotlin-native/backend.native/tests/build.gradle b/kotlin-native/backend.native/tests/build.gradle index f14ae027cb1..a6592fb5aaf 100644 --- a/kotlin-native/backend.native/tests/build.gradle +++ b/kotlin-native/backend.native/tests/build.gradle @@ -3530,15 +3530,14 @@ standaloneTest("testing_filtered_suites") { ["A.*"], // filter out a top-level suite. ["*.common"], // run a test from all suites -> all hooks executed. ["Ignored.*"], // an ignored suite -> no hooks executed. - ["A.ignored"] // a suite with only ignored tests. - // TODO: Currently we execute hooks while other frameworks don't. Fix it. + ["A.ignored"] // a suite with only ignored tests -> no hooks executed. ] def expectedHooks = [ ["Filtered_suitesKt.before", "Filtered_suitesKt.after"], ["A.before", "A.after"], ["A.before", "A.after", "Filtered_suitesKt.before", "Filtered_suitesKt.after"], [], - ["A.before", "A.after"], // TODO: fix it. + [] ] multiRuns = true diff --git a/kotlin-native/runtime/src/main/kotlin/kotlin/native/internal/test/TestRunner.kt b/kotlin-native/runtime/src/main/kotlin/kotlin/native/internal/test/TestRunner.kt index d254458da16..97ecbcd482e 100644 --- a/kotlin-native/runtime/src/main/kotlin/kotlin/native/internal/test/TestRunner.kt +++ b/kotlin-native/runtime/src/main/kotlin/kotlin/native/internal/test/TestRunner.kt @@ -225,6 +225,15 @@ internal class TestRunner(val suites: List, args: Array) { } private fun TestSuite.run() { + // Do not run @BeforeClass/@AfterClass hooks if all test cases are ignored. + if (testCases.values.all { it.ignored }) { + testCases.values.forEach { testCase -> + sendToListeners { ignore(testCase) } + } + return + } + + // Normal path: run all hooks and execute test cases. doBeforeClass() testCases.values.forEach { testCase -> if (testCase.ignored) {