-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Add removing stack traces for simple report (#1931)
- Loading branch information
1 parent
d5ccc52
commit c924773
Showing
5 changed files
with
85 additions
and
47 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
15 changes: 15 additions & 0 deletions
15
test_runner/src/main/kotlin/ftl/domain/junit/StackTraceRemover.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,15 @@ | ||
package ftl.domain.junit | ||
|
||
import ftl.api.JUnitTest | ||
|
||
fun JUnitTest.Result.removeStackTraces() = copy(testsuites = testsuites?.removeStackTraces()) | ||
|
||
private fun MutableCollection<JUnitTest.Suite>.removeStackTraces() = map { testSuite -> | ||
testSuite.copy(testcases = testSuite.testcases?.withRemovedStackTraces()) | ||
}.toMutableList() | ||
|
||
private fun MutableCollection<JUnitTest.Case>.withRemovedStackTraces() = | ||
map { testCase -> testCase.removeFlakyStackTrace() }.toMutableList() | ||
|
||
private fun JUnitTest.Case.removeFlakyStackTrace(): JUnitTest.Case = | ||
if (flaky == true) copy(errors = null, failures = null) else this |
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
68 changes: 68 additions & 0 deletions
68
test_runner/src/test/kotlin/ftl/domain/junit/StackTraceRemoverTest.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,68 @@ | ||
package ftl.domain.junit | ||
|
||
import com.google.common.truth.Truth.assertThat | ||
import ftl.api.JUnitTest | ||
import org.junit.Test | ||
|
||
class StackTraceRemoverTest { | ||
|
||
val testcases = mutableListOf( | ||
JUnitTest.Case("name", "class", "time", failures = listOf("fail"), errors = listOf("error")), | ||
JUnitTest.Case("name2", "class2", "time2", failures = listOf("fail2"), errors = listOf("error2")), | ||
) | ||
|
||
@Test | ||
fun `Should remove stack traces for flaky tests`() { | ||
// given | ||
val testcases = mutableListOf( | ||
JUnitTest.Case("name", "class", "time", failures = listOf("fail"), errors = listOf("error")), | ||
JUnitTest.Case("name2", "class2", "time2", failures = listOf("fail2"), errors = listOf("error2")), | ||
) | ||
val junitTestResult = testResultsFor(testcases, flaky = true) | ||
|
||
// when | ||
val actual = junitTestResult.removeStackTraces() | ||
|
||
// then | ||
actual.testsuites?.forEach { suite -> | ||
assertThat(suite.testcases?.all { testCase -> testCase.failures == null }).isTrue() | ||
assertThat(suite.testcases?.all { testCase -> testCase.errors == null }).isTrue() | ||
} | ||
} | ||
|
||
@Test | ||
fun `Should not remove stack traces for not flaky test`() { | ||
// given | ||
val junitTestResult = testResultsFor(testcases, flaky = false) | ||
|
||
// when | ||
val actual = junitTestResult.removeStackTraces() | ||
|
||
// then | ||
actual.testsuites?.forEach { suite -> | ||
assertThat(suite.testcases?.all { testCase -> testCase.failures == null }).isFalse() | ||
assertThat(suite.testcases?.all { testCase -> testCase.errors == null }).isFalse() | ||
} | ||
} | ||
|
||
private fun testResultsFor(testCases: MutableList<JUnitTest.Case>, flaky: Boolean) = JUnitTest.Result( | ||
testsuites = mutableListOf( | ||
JUnitTest.Suite( | ||
"", | ||
"-1", | ||
"-1", | ||
-1, | ||
"-1", | ||
"-1", | ||
"-1", | ||
"-1", | ||
"-1", | ||
"-1", | ||
testCases.onEach { it.apply { this.flaky = flaky } }, | ||
null, | ||
null, | ||
null | ||
) | ||
) | ||
) | ||
} |
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