Skip to content

Commit

Permalink
[SUREFIRE-2277] Add flakes to the failsafe-summary.xml. Fix a bug in …
Browse files Browse the repository at this point in the history
…the equals method for RunResult where it did not account for the flakes field.
  • Loading branch information
bxu-atl committed Oct 29, 2024
1 parent 91d16c3 commit 85d733a
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public final class FailsafeSummaryXmlUtils {
+ " <errors>%d</errors>\n"
+ " <failures>%d</failures>\n"
+ " <skipped>%d</skipped>\n"
+ " <flakes>%d</flakes>\n"
+ " %s\n"
+ "</failsafe-summary>";

Expand All @@ -84,12 +85,14 @@ public static RunResult toRunResult(File failsafeSummaryXml) throws Exception {
String skipped = xpath.evaluate("/failsafe-summary/skipped", root);
String failureMessage = xpath.evaluate("/failsafe-summary/failureMessage", root);
String timeout = xpath.evaluate("/failsafe-summary/@timeout", root);
String flakes = xpath.evaluate("/failsafe-summary/flakes", root);

return new RunResult(
parseInt(completed),
parseInt(errors),
parseInt(failures),
parseInt(skipped),
isBlank(flakes) ? 0 : parseInt(flakes),
isBlank(failureMessage) ? null : unescapeXml(failureMessage),
parseBoolean(timeout));
}
Expand All @@ -107,6 +110,7 @@ public static void fromRunResultToFile(RunResult fromRunResult, File toFailsafeS
fromRunResult.getErrors(),
fromRunResult.getFailures(),
fromRunResult.getSkipped(),
fromRunResult.getFlakes(),
msg);

Files.write(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,17 @@
package org.apache.maven.plugin.failsafe;

import java.io.File;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;
import java.util.Locale;

import org.apache.maven.plugin.failsafe.util.FailsafeSummaryXmlUtils;
import org.apache.maven.surefire.api.suite.RunResult;
import org.apache.maven.surefire.api.util.SureFireFileManager;
import org.junit.Test;

import static java.lang.String.format;
import static org.assertj.core.api.Assertions.assertThat;

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

@Test
public void testFlakes() throws Exception {
writeReadCheck(new RunResult(3, 2, 1, 0, 2, null, true));
}

@Test
public void testLegacyDeserialization() throws Exception {
File legacySummary = SureFireFileManager.createTempFile("failsafe", "test");
String legacyFailsafeSummaryXmlTemplate = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<failsafe-summary xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
+ " xsi:noNamespaceSchemaLocation=\"https://maven.apache.org/surefire/maven-surefire-plugin/xsd/failsafe-summary.xsd\""
+ " result=\"%s\" timeout=\"%s\">\n"
+ " <completed>%d</completed>\n"
+ " <errors>%d</errors>\n"
+ " <failures>%d</failures>\n"
+ " <skipped>%d</skipped>\n"
+ " %s\n"
+ "</failsafe-summary>";
String xml = format(Locale.ROOT, legacyFailsafeSummaryXmlTemplate, 0, false, 3, 2, 1, 0, "msg");
Files.write(
legacySummary.toPath(),
xml.getBytes(StandardCharsets.UTF_8),
StandardOpenOption.CREATE,
StandardOpenOption.TRUNCATE_EXISTING,
StandardOpenOption.WRITE);

// When the failsafe-summary.xml does not contain the <flakes> element, it should be considered as 0.
RunResult expected = new RunResult(3, 2, 1, 0, 0, null, false);
RunResult actual = FailsafeSummaryXmlUtils.toRunResult(legacySummary);

assertThat(actual.getCompletedCount()).isEqualTo(expected.getCompletedCount());

assertThat(actual.getErrors()).isEqualTo(expected.getErrors());

assertThat(actual.getFailures()).isEqualTo(expected.getFailures());

assertThat(actual.getSkipped()).isEqualTo(expected.getSkipped());

assertThat(actual.getFlakes()).isEqualTo(expected.getFlakes());

assertThat(actual).isEqualTo(expected);
}

@Test
public void testAppendSerialization() throws Exception {
RunResult simpleAggregate = getSimpleAggregate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<xsd:element name="errors" type="xsd:int"/>
<xsd:element name="failures" type="xsd:int"/>
<xsd:element name="skipped" type="xsd:int"/>
<xsd:element name="flakes" type="xsd:int" nillable="true"/>
<xsd:element name="failureMessage" type="xsd:string" nillable="true"/>
</xsd:sequence>
<xsd:attribute name="result" type="errorType" use="optional"/>
Expand All @@ -38,4 +39,3 @@
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>

Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ public boolean equals(Object o) {
if (skipped != runResult.skipped) {
return false;
}
if (flakes != runResult.flakes) {
return false;
}
if (timeout != runResult.timeout) {
return false;
}
Expand Down

0 comments on commit 85d733a

Please sign in to comment.