Skip to content

Commit 923d791

Browse files
authored
fix: resolve flaky tests counts discrepancy (#2536)
1 parent d2f3a51 commit 923d791

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

test_runner/src/main/kotlin/ftl/domain/junit/JUnitTestMerge.kt

+7
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ fun JUnitTest.Suite.merge(other: JUnitTest.Suite): JUnitTest.Suite {
4747
this.errors = mergeInt(this.errors, other.errors)
4848
this.skipped = mergeInt(this.skipped, other.skipped)
4949
this.time = mergeDouble(this.time, other.time)
50+
if (other.flakes != null) {
51+
this.flakes = mergeInt(
52+
this.flakes?.toString(),
53+
other.flakes?.toString()
54+
).toInt()
55+
}
56+
5057

5158
if (this.testcases == null) this.testcases = mutableListOf()
5259
if (other.testcases?.isNotEmpty() == true) {

test_runner/src/test/kotlin/ftl/client/xml/JUnitXmlTest.kt

+35
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ class JUnitXmlTest {
3030
<skipped/>
3131
</testcase>
3232
<testcase name="testPasses" classname="com.example.app.ExampleUiTest" time="0.001"/>
33+
</testsuite>
34+
""".trimIndent()
35+
val flakyTestSuiteXml = """
36+
<testsuite name="" tests="2" failures="0" flakes="1" errors="0" skipped="0" time="0.026" timestamp="2018-10-26T19:57:28" hostname="localhost">
37+
<properties/>
38+
<testcase name="testFails" classname="com.example.app.ExampleUiTest" time="0.0">
39+
<skipped/>
40+
</testcase>
41+
<testcase name="testPasses" classname="com.example.app.ExampleUiTest" time="0.001"/>
3342
</testsuite>
3443
""".trimIndent()
3544
}
@@ -525,6 +534,32 @@ junit.framework.Assert.fail(Assert.java:50)</failure>
525534
val oneSuiteXml = parseOneSuiteXml(crashingOneSuiteMessage.writeToTempFile()).toXmlString().trimIndent()
526535
Assert.assertEquals("One Suite Messages should be the same!", expectedOneSuiteMessage, oneSuiteXml)
527536
}
537+
538+
@Test
539+
fun `merge flakes`() {
540+
val merged = parseOneSuiteXml(flakyTestSuiteXml.writeToTempFile())
541+
merged.merge(merged)
542+
val actual = merged.toXmlString().normalizeLineEnding()
543+
544+
assertThat(actual).isEqualTo(
545+
"""
546+
<?xml version='1.0' encoding='UTF-8' ?>
547+
<testsuites>
548+
<testsuite name="" tests="4" failures="0" flakes="2" errors="0" skipped="0" time="0.052" timestamp="2018-10-26T19:57:28" hostname="localhost">
549+
<testcase name="testFails" classname="com.example.app.ExampleUiTest" time="0.0">
550+
<skipped/>
551+
</testcase>
552+
<testcase name="testPasses" classname="com.example.app.ExampleUiTest" time="0.001"/>
553+
<testcase name="testFails" classname="com.example.app.ExampleUiTest" time="0.0">
554+
<skipped/>
555+
</testcase>
556+
<testcase name="testPasses" classname="com.example.app.ExampleUiTest" time="0.001"/>
557+
</testsuite>
558+
</testsuites>
559+
560+
""".trimIndent()
561+
)
562+
}
528563
}
529564

530565
private fun String.writeToTempFile(): File = File.createTempFile("temp", "test")

0 commit comments

Comments
 (0)