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