[Native][tests] Remove unnecesary common prefix in dynamic test names

This commit is contained in:
Dmitriy Dolovov
2021-12-01 20:55:28 +03:00
parent 4a4760dc4b
commit 7981cf8368
3 changed files with 25 additions and 15 deletions
@@ -68,22 +68,24 @@ abstract class AbstractNativeBlackBoxTest {
* This function should be called from a method annotated with [org.junit.jupiter.api.TestFactory]. * This function should be called from a method annotated with [org.junit.jupiter.api.TestFactory].
*/ */
internal fun dynamicTestCase(testCaseId: TestCaseId): Collection<DynamicNode> { internal fun dynamicTestCase(testCaseId: TestCaseId): Collection<DynamicNode> {
val rootTestRunNode = testRunProvider.getTestRuns(testCaseId) val testRunNodes = testRunProvider.getTestRuns(testCaseId)
return buildJUnitDynamicNodes(rootTestRunNode) return buildJUnitDynamicNodes(testRunNodes)
} }
// We have to use planar (one-level) tree of JUnit5 dynamic nodes, because Gradle does not support yet rendering // We have to use planar (one-level) tree of JUnit5 dynamic nodes, because Gradle does not support yet rendering
// tests with arbitrary nesting level in their test reports. As long as these reports are consumed by various CI (such as TeamCity) // tests with arbitrary nesting level in their test reports. As long as these reports are consumed by various CI (such as TeamCity)
// we have almost no chance to display test results in CI properly. // we have almost no chance to display test results in CI properly.
private fun buildJUnitDynamicNodes(testRunNode: TreeNode<TestRun>): Collection<DynamicNode> = private fun buildJUnitDynamicNodes(testRunNodes: Collection<TreeNode<TestRun>>): Collection<DynamicNode> =
// This is the proper implementation that should be used instead: // This is the proper implementation that should be used instead:
// buildList { // buildList {
// testRunNode.items.mapTo(this) { testRun -> // testRunNodes.forEach { testRunNode ->
// dynamicTest(testRun.displayName) { runTest(testRun) } // testRunNode.items.mapTo(this) { testRun ->
// } // dynamicTest(testRun.displayName) { runTest(testRun) }
// }
// //
// testRunNode.children.mapTo(this) { childTestRunNode -> // testRunNode.children.mapTo(this) { childTestRunNode ->
// dynamicContainer(childTestRunNode.packageSegment, buildJUnitDynamicNodes(childTestRunNode)) // dynamicContainer(childTestRunNode.packageSegment, buildJUnitDynamicNodes(childTestRunNode))
// }
// } // }
// } // }
buildList { buildList {
@@ -97,7 +99,7 @@ abstract class AbstractNativeBlackBoxTest {
children.forEach { it.processItems(ownPackageSegment) } children.forEach { it.processItems(ownPackageSegment) }
} }
testRunNode.processItems("") testRunNodes.forEach { testRunNode -> testRunNode.processItems("") }
} }
private fun performTestRun(testRun: TestRun) { private fun performTestRun(testRun: TestRun) {
@@ -98,7 +98,9 @@ internal class TestRunProvider(
* } * }
* } * }
*/ */
fun getTestRuns(testCaseId: TestCaseId): TreeNode<TestRun> = withTestExecutable(testCaseId) { testCase, executable, cacheKey -> fun getTestRuns(
testCaseId: TestCaseId
): Collection<TreeNode<TestRun>> = withTestExecutable(testCaseId) { testCase, executable, cacheKey ->
fun createTestRun(testRunName: String, testFunction: TestFunction?): TestRun { fun createTestRun(testRunName: String, testFunction: TestFunction?): TestRun {
val runParameters = getRunParameters(testCase, testFunction) val runParameters = getRunParameters(testCase, testFunction)
return TestRun(testRunName, executable, runParameters, testCase.id) return TestRun(testRunName, executable, runParameters, testCase.id)
@@ -15,15 +15,15 @@ internal interface TreeNode<T> {
companion object { companion object {
fun <T> oneLevel(vararg items: T) = oneLevel(listOf(*items)) fun <T> oneLevel(vararg items: T) = oneLevel(listOf(*items))
fun <T> oneLevel(items: Iterable<T>) = object : TreeNode<T> { fun <T> oneLevel(items: Iterable<T>): List<TreeNode<T>> = listOf(object : TreeNode<T> {
override val packageSegment get() = "" override val packageSegment get() = ""
override val items = items.toList() override val items = items.toList()
override val children get() = emptyList<TreeNode<T>>() override val children get() = emptyList<TreeNode<T>>()
} })
} }
} }
internal fun <T, R> Collection<T>.buildTree(extractPackageName: (T) -> PackageFQN, transform: (T) -> R): TreeNode<R> { internal fun <T, R> Collection<T>.buildTree(extractPackageName: (T) -> PackageFQN, transform: (T) -> R): Collection<TreeNode<R>> {
val groupedItems: Map<PackageFQN, List<R>> = groupBy(extractPackageName).mapValues { (_, items) -> items.map(transform) } val groupedItems: Map<PackageFQN, List<R>> = groupBy(extractPackageName).mapValues { (_, items) -> items.map(transform) }
// Fast pass. // Fast pass.
@@ -44,8 +44,14 @@ internal fun <T, R> Collection<T>.buildTree(extractPackageName: (T) -> PackageFQ
node.items += items node.items += items
} }
// Skip meaningless nodes starting from the root. Compress the resulting tree. // Skip meaningless nodes starting from the root.
return root.skipMeaninglessNodes().apply { compress() } val meaningfulNode = root.skipMeaninglessNodes().apply { compress() }
// Compress the resulting tree.
return if (meaningfulNode.items.isNotEmpty() || meaningfulNode.childrenMap.isEmpty())
listOf(meaningfulNode)
else
meaningfulNode.childrenMap.values
} }
private class TreeBuilder<T>(override var packageSegment: String) : TreeNode<T> { private class TreeBuilder<T>(override var packageSegment: String) : TreeNode<T> {