[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:
committed by
Vasily Levchenko
parent
4f037b8b81
commit
e45c2d31bc
@@ -3530,15 +3530,14 @@ standaloneTest("testing_filtered_suites") {
|
|||||||
["A.*"], // filter out a top-level suite.
|
["A.*"], // filter out a top-level suite.
|
||||||
["*.common"], // run a test from all suites -> all hooks executed.
|
["*.common"], // run a test from all suites -> all hooks executed.
|
||||||
["Ignored.*"], // an ignored suite -> no hooks executed.
|
["Ignored.*"], // an ignored suite -> no hooks executed.
|
||||||
["A.ignored"] // a suite with only ignored tests.
|
["A.ignored"] // a suite with only ignored tests -> no hooks executed.
|
||||||
// TODO: Currently we execute hooks while other frameworks don't. Fix it.
|
|
||||||
]
|
]
|
||||||
def expectedHooks = [
|
def expectedHooks = [
|
||||||
["Filtered_suitesKt.before", "Filtered_suitesKt.after"],
|
["Filtered_suitesKt.before", "Filtered_suitesKt.after"],
|
||||||
["A.before", "A.after"],
|
["A.before", "A.after"],
|
||||||
["A.before", "A.after", "Filtered_suitesKt.before", "Filtered_suitesKt.after"],
|
["A.before", "A.after", "Filtered_suitesKt.before", "Filtered_suitesKt.after"],
|
||||||
[],
|
[],
|
||||||
["A.before", "A.after"], // TODO: fix it.
|
[]
|
||||||
]
|
]
|
||||||
|
|
||||||
multiRuns = true
|
multiRuns = true
|
||||||
|
|||||||
@@ -225,6 +225,15 @@ internal class TestRunner(val suites: List<TestSuite>, args: Array<String>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun TestSuite.run() {
|
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()
|
doBeforeClass()
|
||||||
testCases.values.forEach { testCase ->
|
testCases.values.forEach { testCase ->
|
||||||
if (testCase.ignored) {
|
if (testCase.ignored) {
|
||||||
|
|||||||
Reference in New Issue
Block a user