[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.
This commit is contained in:
Ilya Matveev
2021-02-03 13:29:46 +07:00
committed by Vasily Levchenko
parent 4f037b8b81
commit e45c2d31bc
2 changed files with 11 additions and 3 deletions
@@ -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
@@ -225,6 +225,15 @@ internal class TestRunner(val suites: List<TestSuite>, args: Array<String>) {
}
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) {