Skip to content

Commit d0887a5

Browse files
committed
Issue #237 parse flakyFailure and rerunFailure
Signed-off-by: Olivier Lamy <[email protected]>
1 parent 710aafd commit d0887a5

File tree

5 files changed

+29
-25
lines changed

5 files changed

+29
-25
lines changed

src/main/java/hudson/tasks/junit/CaseResult.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ public class CaseResult extends TestResult implements Comparable<CaseResult> {
8484
private String errorStackTrace;
8585
private String errorDetails;
8686
private Map<String, String> properties;
87-
private List<FlakyFailure> flakyFailures = new ArrayList<>();
88-
private List<RerunFailure> rerunFailures = new ArrayList<>();
87+
private FlakyFailure[] flakyFailures;
88+
private RerunFailure[] rerunFailures;
8989

9090
@SuppressFBWarnings(value = "SE_TRANSIENT_FIELD_NOT_RESTORED", justification = "Specific method to restore it")
9191
private transient SuiteResult parent;
@@ -273,7 +273,7 @@ public static float clampDuration(float d) {
273273
return Math.min(365.0f * 24 * 60 * 60, Math.max(0.0f, d));
274274
}
275275

276-
static List<FlakyFailure> parseFlakyFailures(Element testCase) {
276+
private static FlakyFailure[] parseFlakyFailures(Element testCase) {
277277
List<FlakyFailure> flakyFailures = new ArrayList<>();
278278
List<Element> flakyFailuresElements = testCase.elements("flakyFailure");
279279
if (flakyFailuresElements != null) {
@@ -286,10 +286,10 @@ static List<FlakyFailure> parseFlakyFailures(Element testCase) {
286286
flakyFailures.add(new FlakyFailure(message, type, stackTrace, stdout, stderr));
287287
}
288288
}
289-
return flakyFailures;
289+
return flakyFailures.isEmpty() ? null : flakyFailures.toArray(new FlakyFailure[0]);
290290
}
291291

292-
static List<RerunFailure> parseRerunFailures(Element testCase) {
292+
private static RerunFailure[] parseRerunFailures(Element testCase) {
293293
List<RerunFailure> rerunFailures = new ArrayList<>();
294294
List<Element> rerunFailureElements = testCase.elements("rerunFailure");
295295
if (rerunFailureElements != null) {
@@ -302,7 +302,7 @@ static List<RerunFailure> parseRerunFailures(Element testCase) {
302302
rerunFailures.add(new RerunFailure(message, type, stackTrace, stdout, stderr));
303303
}
304304
}
305-
return rerunFailures;
305+
return rerunFailures.isEmpty() ? null : rerunFailures.toArray(new RerunFailure[0]);
306306
}
307307

308308
static CaseResult parse(SuiteResult parent, final XMLStreamReader reader, String context, String ver)
@@ -1076,11 +1076,11 @@ void replaceParent(SuiteResult parent) {
10761076
this.parent = parent;
10771077
}
10781078

1079-
public List<FlakyFailure> getFlakyFailures() {
1079+
public @CheckForNull FlakyFailure[] getFlakyFailures() {
10801080
return flakyFailures;
10811081
}
10821082

1083-
public List<RerunFailure> getRerunFailures() {
1083+
public @CheckForNull RerunFailure[] getRerunFailures() {
10841084
return rerunFailures;
10851085
}
10861086

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package hudson.tasks.junit;
2+
3+
import java.io.Serializable;
4+
5+
public record FlakyFailure(String message, String type, String stackTrace, String stdout, String stderr)
6+
implements Serializable {}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package hudson.tasks.junit;
2+
3+
import java.io.Serializable;
4+
5+
public record RerunFailure(String message, String type, String stackTrace, String stdout, String stderr)
6+
implements Serializable {}

src/test/java/hudson/tasks/junit/TestResultTest.java

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -480,16 +480,12 @@ void includeFlakyAndRerun() throws IOException, URISyntaxException {
480480
assertNotNull(flakySuiteResult);
481481
assertEquals(
482482
2,
483-
flakySuiteResult
484-
.getCase("io.olamy.FlakyTest.testApp")
485-
.getFlakyFailures()
486-
.size(),
483+
flakySuiteResult.getCase("io.olamy.FlakyTest.testApp").getFlakyFailures().length,
487484
"Wrong number of flayfailures");
488485

489-
FlakyFailure flakyFailure = flakySuiteResult
490-
.getCase("io.olamy.FlakyTest.testApp")
491-
.getFlakyFailures()
492-
.get(0);
486+
FlakyFailure flakyFailure =
487+
flakySuiteResult.getCase("io.olamy.FlakyTest.testApp").getFlakyFailures()[0];
488+
assertNotNull(flakyFailure);
493489
assertEquals("junit.framework.AssertionFailedError", flakyFailure.type());
494490
assertEquals("obvious fail", flakyFailure.message());
495491
assertTrue(flakyFailure.stackTrace().contains("at io.olamy.FlakyTest.testApp(FlakyTest.java:27)"));
@@ -502,16 +498,12 @@ void includeFlakyAndRerun() throws IOException, URISyntaxException {
502498
assertNotNull(rerunSuite);
503499
assertEquals(
504500
3,
505-
rerunSuite
506-
.getCase("io.olamy.AlwaysFailTest.testApp")
507-
.getRerunFailures()
508-
.size(),
501+
rerunSuite.getCase("io.olamy.AlwaysFailTest.testApp").getRerunFailures().length,
509502
"Wrong number of rerun failures");
510503

511-
RerunFailure rerunFailure = rerunSuite
512-
.getCase("io.olamy.AlwaysFailTest.testApp")
513-
.getRerunFailures()
514-
.get(0);
504+
RerunFailure rerunFailure =
505+
rerunSuite.getCase("io.olamy.AlwaysFailTest.testApp").getRerunFailures()[0];
506+
assertNotNull(rerunFailure);
515507
assertEquals("junit.framework.AssertionFailedError", rerunFailure.type());
516508
assertEquals("built to fail", rerunFailure.message());
517509
assertTrue(

src/test/resources/hudson/tasks/junit/gh-237/TEST-io.olamy.AlwaysFailTest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
]]></system-out>
8686
<system-err><![CDATA[this will really fail
8787
]]></system-err>
88-
<rerunFailure message="built to fail" type="junit.framework.AssertionFailedError">
88+
<rerunFailure message="built to fail" type="junit.framework.AssertionFailedError">
8989
<stackTrace><![CDATA[junit.framework.AssertionFailedError: built to fail
9090
at junit.framework.Assert.fail(Assert.java:57)
9191
at junit.framework.Assert.assertTrue(Assert.java:22)

0 commit comments

Comments
 (0)