-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge test method duration for a given classes
- Loading branch information
Showing
6 changed files
with
88 additions
and
4 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
17 changes: 17 additions & 0 deletions
17
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,17 @@ | ||
package flank.junit.internal | ||
|
||
import flank.junit.JUnit | ||
|
||
internal fun List<JUnit.TestResult>.mergeDurations( | ||
forClasses: Set<String> | ||
): List<JUnit.TestResult> = | ||
if (forClasses.isEmpty()) this | ||
else groupBy { testResult -> testResult.className in forClasses }.run { | ||
getOrDefault(false, emptyList()) + getOrDefault(true, emptyList()) | ||
.groupBy { testResult -> testResult.className }.values | ||
.map { group -> | ||
group.sortedBy { it.startAt } | ||
.reduce { acc, testResult -> acc.copy(endsAt = testResult.endsAt) } | ||
.run { copy(testName = "") } | ||
} | ||
} |
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
51 changes: 51 additions & 0 deletions
51
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,51 @@ | ||
package flank.junit.internal | ||
|
||
import flank.junit.JUnit | ||
import flank.junit.mergeTestCases | ||
import org.junit.Assert | ||
import org.junit.Test | ||
|
||
class MergeDurationsKtTest { | ||
|
||
@Test | ||
fun test() { | ||
// given | ||
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(setOf("b", "d")) | ||
|
||
// 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 = "", | ||
) |