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) {