Skip to content

Commit d24adb4

Browse files
bxu-atlmichael-o
authored andcommitted
[SUREFIRE-2277] RunResult#getFlakes() is lost during serialisation/deserialisation to/from failsafe-summary.xml
This closes #790
1 parent 4385e94 commit d24adb4

File tree

4 files changed

+59
-0
lines changed

4 files changed

+59
-0
lines changed

maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/util/FailsafeSummaryXmlUtils.java

+6
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public final class FailsafeSummaryXmlUtils {
6464
+ " <errors>%d</errors>\n"
6565
+ " <failures>%d</failures>\n"
6666
+ " <skipped>%d</skipped>\n"
67+
+ " <flakes>%d</flakes>\n"
6768
+ " %s\n"
6869
+ "</failsafe-summary>";
6970

@@ -84,12 +85,16 @@ public static RunResult toRunResult(File failsafeSummaryXml) throws Exception {
8485
String skipped = xpath.evaluate("/failsafe-summary/skipped", root);
8586
String failureMessage = xpath.evaluate("/failsafe-summary/failureMessage", root);
8687
String timeout = xpath.evaluate("/failsafe-summary/@timeout", root);
88+
String flakes = xpath.evaluate("/failsafe-summary/flakes", root);
8789

8890
return new RunResult(
8991
parseInt(completed),
9092
parseInt(errors),
9193
parseInt(failures),
9294
parseInt(skipped),
95+
// FIXME Backwards compatability: to be replaced with parseInt in a future release
96+
// synchronize with maven-surefire-plugin/src/site/resources/xsd/failsafe-summary.xsd
97+
isBlank(flakes) ? 0 : parseInt(flakes),
9398
isBlank(failureMessage) ? null : unescapeXml(failureMessage),
9499
parseBoolean(timeout));
95100
}
@@ -107,6 +112,7 @@ public static void fromRunResultToFile(RunResult fromRunResult, File toFailsafeS
107112
fromRunResult.getErrors(),
108113
fromRunResult.getFailures(),
109114
fromRunResult.getSkipped(),
115+
fromRunResult.getFlakes(),
110116
msg);
111117

112118
Files.write(

maven-failsafe-plugin/src/test/java/org/apache/maven/plugin/failsafe/RunResultTest.java

+48
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,17 @@
1919
package org.apache.maven.plugin.failsafe;
2020

2121
import java.io.File;
22+
import java.nio.charset.StandardCharsets;
23+
import java.nio.file.Files;
24+
import java.nio.file.StandardOpenOption;
25+
import java.util.Locale;
2226

2327
import org.apache.maven.plugin.failsafe.util.FailsafeSummaryXmlUtils;
2428
import org.apache.maven.surefire.api.suite.RunResult;
2529
import org.apache.maven.surefire.api.util.SureFireFileManager;
2630
import org.junit.Test;
2731

32+
import static java.lang.String.format;
2833
import static org.assertj.core.api.Assertions.assertThat;
2934

3035
/**
@@ -64,6 +69,49 @@ public void testSkipped() throws Exception {
6469
writeReadCheck(new RunResult(3, 2, 1, 0, null, true));
6570
}
6671

72+
@Test
73+
public void testFlakes() throws Exception {
74+
writeReadCheck(new RunResult(3, 2, 1, 0, 2, null, true));
75+
}
76+
77+
@Test
78+
public void testLegacyDeserialization() throws Exception {
79+
File legacySummary = SureFireFileManager.createTempFile("failsafe", "test");
80+
String legacyFailsafeSummaryXmlTemplate = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
81+
+ "<failsafe-summary xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
82+
+ " xsi:noNamespaceSchemaLocation=\"https://maven.apache.org/surefire/maven-surefire-plugin/xsd/failsafe-summary.xsd\""
83+
+ " result=\"%s\" timeout=\"%s\">\n"
84+
+ " <completed>%d</completed>\n"
85+
+ " <errors>%d</errors>\n"
86+
+ " <failures>%d</failures>\n"
87+
+ " <skipped>%d</skipped>\n"
88+
+ " %s\n"
89+
+ "</failsafe-summary>";
90+
String xml = format(Locale.ROOT, legacyFailsafeSummaryXmlTemplate, 0, false, 3, 2, 1, 0, "msg");
91+
Files.write(
92+
legacySummary.toPath(),
93+
xml.getBytes(StandardCharsets.UTF_8),
94+
StandardOpenOption.CREATE,
95+
StandardOpenOption.TRUNCATE_EXISTING,
96+
StandardOpenOption.WRITE);
97+
98+
// When the failsafe-summary.xml does not contain the <flakes> element, it should be considered as 0.
99+
RunResult expected = new RunResult(3, 2, 1, 0, 0, null, false);
100+
RunResult actual = FailsafeSummaryXmlUtils.toRunResult(legacySummary);
101+
102+
assertThat(actual.getCompletedCount()).isEqualTo(expected.getCompletedCount());
103+
104+
assertThat(actual.getErrors()).isEqualTo(expected.getErrors());
105+
106+
assertThat(actual.getFailures()).isEqualTo(expected.getFailures());
107+
108+
assertThat(actual.getSkipped()).isEqualTo(expected.getSkipped());
109+
110+
assertThat(actual.getFlakes()).isEqualTo(expected.getFlakes());
111+
112+
assertThat(actual).isEqualTo(expected);
113+
}
114+
67115
@Test
68116
public void testAppendSerialization() throws Exception {
69117
RunResult simpleAggregate = getSimpleAggregate();

maven-surefire-plugin/src/site/resources/xsd/failsafe-summary.xsd

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<xsd:element name="errors" type="xsd:int"/>
2626
<xsd:element name="failures" type="xsd:int"/>
2727
<xsd:element name="skipped" type="xsd:int"/>
28+
<xsd:element name="flakes" type="xsd:int" minOccurs="0"/>
2829
<xsd:element name="failureMessage" type="xsd:string" nillable="true"/>
2930
</xsd:sequence>
3031
<xsd:attribute name="result" type="errorType" use="optional"/>

surefire-api/src/main/java/org/apache/maven/surefire/api/suite/RunResult.java

+4
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ public boolean equals(Object o) {
202202
if (skipped != runResult.skipped) {
203203
return false;
204204
}
205+
if (flakes != runResult.flakes) {
206+
return false;
207+
}
205208
if (timeout != runResult.timeout) {
206209
return false;
207210
}
@@ -218,6 +221,7 @@ public int hashCode() {
218221
result = 31 * result + errors;
219222
result = 31 * result + failures;
220223
result = 31 * result + skipped;
224+
result = 31 * result + flakes;
221225
result = 31 * result + (failure != null ? failure.hashCode() : 0);
222226
result = 31 * result + (timeout ? 1 : 0);
223227
return result;

0 commit comments

Comments
 (0)