-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Merge test method duration for parameterized classes (#2062)
Fixes #2052 ## Changes * Adds to module `:tool:junit` function for merging test methods into test-class with accumulated duration. * Merges test methods for given class names while loading previous durations. ## Test Plan > How do we know the code works? Build flank: ```shell . .env flankScripts assemble flank -d ``` Run the following command twice: ```shell flank corellium test android run -c="./test_configs/flank-corellium.yml" ``` The second run should calculate durations for parameterized classes. Check generated `android-shards.json` each parameterized class should have a duration different than the default (120). ## Checklist - [x] Documented - [x] Unit tested
- Loading branch information
Showing
7 changed files
with
272 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
tool/junit/src/main/kotlin/flank/junit/internal/MergeDurations.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package flank.junit.internal | ||
|
||
import flank.junit.JUnit | ||
|
||
internal fun List<JUnit.TestResult>.mergeDurations( | ||
forClasses: Set<String> | ||
): List<JUnit.TestResult> = | ||
if (isEmpty() || forClasses.isEmpty()) this // Nothing to merge. | ||
else groupBy { method -> method.className in forClasses }.run { // separate test cases methods to merge. | ||
getOrDefault(false, emptyList()) + getOrDefault(true, emptyList()) // Sum test cases methods with classes. | ||
.groupBy { method -> method.className }.values // Group tests cases to merge by class name. | ||
.map { methods -> methods.sortedBy(JUnit.TestResult::startAt) } // Ensure correct order. | ||
.map { methods -> methods.first().copy(testName = "", endsAt = methods.last().endsAt) } // Merge into class. | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
tool/junit/src/test/kotlin/flank/junit/internal/MergeDurationsKtTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
package flank.junit.internal | ||
|
||
import flank.junit.JUnit | ||
import flank.junit.mergeTestCases | ||
import org.junit.Assert | ||
import org.junit.Test | ||
|
||
class MergeDurationsKtTest { | ||
|
||
/** | ||
* Only test case methods of classes specified in set will be merged into classes. | ||
*/ | ||
@Test | ||
fun mixed() { | ||
// given | ||
val classes = setOf("b", "d") | ||
|
||
val results = listOf( | ||
result("a", "a", 0, 10), | ||
result("b", "b[0]", 10, 110), | ||
result("b", "b[1]", 110, 120), | ||
result("b", "b[2]", 120, 140), | ||
result("c", "c", 140, 440), | ||
result("d", "d[name: a]", 440, 470), | ||
result("d", "d[name: b]", 470, 500), | ||
) | ||
|
||
val expected = listOf( | ||
result("a", "a", 0, 10), | ||
result("c", "c", 140, 440), | ||
result("b", "", 10, 140), | ||
result("d", "", 440, 500), | ||
) | ||
|
||
// when | ||
val actual = results.mergeTestCases(classes) | ||
|
||
// then | ||
Assert.assertEquals(expected, actual) | ||
} | ||
|
||
/** | ||
* All test case methods will be merged into test case classes. | ||
*/ | ||
@Test | ||
fun allToMerge() { | ||
// given | ||
val classes = setOf("a", "b", "c", "d") | ||
|
||
val results = listOf( | ||
result("a", "a", 0, 10), | ||
result("b", "b[0]", 10, 110), | ||
result("b", "b[1]", 110, 120), | ||
result("b", "b[2]", 120, 140), | ||
result("c", "c", 140, 440), | ||
result("d", "d[name: a]", 440, 470), | ||
result("d", "d[name: b]", 470, 500), | ||
) | ||
|
||
val expected = listOf( | ||
result("a", "", 0, 10), | ||
result("b", "", 10, 140), | ||
result("c", "", 140, 440), | ||
result("d", "", 440, 500), | ||
) | ||
|
||
// when | ||
val actual = results.mergeTestCases(classes) | ||
|
||
// then | ||
Assert.assertEquals(expected, actual) | ||
} | ||
|
||
/** | ||
* No test cases will be merged, because of missing class name. | ||
*/ | ||
@Test | ||
fun missingClassName() { | ||
// given | ||
val results = listOf( | ||
result("a", "a", 0, 10), | ||
result("c", "c", 20, 60), | ||
) | ||
|
||
val expected = listOf( | ||
result("a", "a", 0, 10), | ||
result("c", "c", 20, 60), | ||
) | ||
|
||
// when | ||
val actual = results.mergeTestCases(setOf("e")) | ||
|
||
// then | ||
Assert.assertEquals(expected, actual) | ||
} | ||
|
||
/** | ||
* No test cases will be merged, because of empty set. | ||
*/ | ||
@Test | ||
fun emptySet() { | ||
// given | ||
val results = listOf( | ||
result("a", "a", 0, 10), | ||
result("c", "c", 20, 60), | ||
) | ||
|
||
val expected = listOf( | ||
result("a", "a", 0, 10), | ||
result("c", "c", 20, 60), | ||
) | ||
|
||
// when | ||
val actual = results.mergeTestCases(setOf()) | ||
|
||
// then | ||
Assert.assertEquals(expected, actual) | ||
} | ||
} | ||
|
||
private fun result( | ||
className: String, | ||
name: String, | ||
start: Long, | ||
end: Long, | ||
) = JUnit.TestResult( | ||
className = className, | ||
testName = name, | ||
startAt = start, | ||
endsAt = end, | ||
stack = emptyList(), | ||
status = JUnit.TestResult.Status.Passed, | ||
suiteName = "", | ||
) |
Oops, something went wrong.