@@ -68,6 +68,12 @@ public class DefaultReporterFactoryTest extends TestCase {
6868
6969 private static final String ERROR = "error" ;
7070
71+ private static final String TEST_BEFORE_ALL_FLAKE = "com.example.FlakyClass" ;
72+
73+ private static final String TEST_BEFORE_ALL_ERROR = "com.example.AlwaysFailClass" ;
74+
75+ private static final String TEST_ERROR_SUFFIX = "-- Time elapsed: 292.2 s <<< ERROR!" ;
76+
7177 public void testMergeTestHistoryResult () throws Exception {
7278 MessageUtils .setColorEnabled (false );
7379 File target = new File (System .getProperty ("user.dir" ), "target" );
@@ -97,7 +103,7 @@ public void testMergeTestHistoryResult() throws Exception {
97103
98104 DefaultReporterFactory factory = new DefaultReporterFactory (reportConfig , reporter );
99105
100- // First run, four tests failed and one passed
106+ // First run, four tests failed and one passed, plus @BeforeAll failure
101107 Queue <TestMethodStats > firstRunStats = new ArrayDeque <>();
102108 firstRunStats .add (new TestMethodStats (TEST_ONE , ReportEntryType .ERROR , new DummyStackTraceWriter (ERROR )));
103109 firstRunStats .add (new TestMethodStats (TEST_TWO , ReportEntryType .ERROR , new DummyStackTraceWriter (ERROR )));
@@ -106,6 +112,11 @@ public void testMergeTestHistoryResult() throws Exception {
106112 firstRunStats .add (
107113 new TestMethodStats (TEST_FOUR , ReportEntryType .FAILURE , new DummyStackTraceWriter (ASSERTION_FAIL )));
108114 firstRunStats .add (new TestMethodStats (TEST_FIVE , ReportEntryType .SUCCESS , null ));
115+ // @BeforeAll failure for a test class that will eventually succeed
116+ firstRunStats .add (new TestMethodStats (
117+ null ,
118+ ReportEntryType .ERROR ,
119+ new DummyStackTraceWriter (TEST_BEFORE_ALL_FLAKE + ".null " + TEST_ERROR_SUFFIX )));
109120
110121 // Second run, two tests passed
111122 Queue <TestMethodStats > secondRunStats = new ArrayDeque <>();
@@ -114,11 +125,21 @@ public void testMergeTestHistoryResult() throws Exception {
114125 secondRunStats .add (new TestMethodStats (TEST_TWO , ReportEntryType .SUCCESS , null ));
115126 secondRunStats .add (new TestMethodStats (TEST_THREE , ReportEntryType .ERROR , new DummyStackTraceWriter (ERROR )));
116127 secondRunStats .add (new TestMethodStats (TEST_FOUR , ReportEntryType .SUCCESS , null ));
128+ // Successful test from the class that had @BeforeAll failure
129+ secondRunStats .add (new TestMethodStats (TEST_BEFORE_ALL_FLAKE + ".testSucceed" , ReportEntryType .SUCCESS , null ));
130+ // @BeforeAll failure for a different class that will stay as error
131+ secondRunStats .add (new TestMethodStats (
132+ null ,
133+ ReportEntryType .ERROR ,
134+ new DummyStackTraceWriter (TEST_BEFORE_ALL_ERROR + ".null " + TEST_ERROR_SUFFIX )));
117135
118136 // Third run, another test passed
119137 Queue <TestMethodStats > thirdRunStats = new ArrayDeque <>();
120138 thirdRunStats .add (new TestMethodStats (TEST_ONE , ReportEntryType .SUCCESS , null ));
121139 thirdRunStats .add (new TestMethodStats (TEST_THREE , ReportEntryType .ERROR , new DummyStackTraceWriter (ERROR )));
140+ // Another @BeforeAll failure for the always-failing class
141+ thirdRunStats .add (new TestMethodStats (
142+ null , ReportEntryType .ERROR , new DummyStackTraceWriter (TEST_BEFORE_ALL_ERROR + ".null" )));
122143
123144 TestSetRunListener firstRunListener = mock (TestSetRunListener .class );
124145 TestSetRunListener secondRunListener = mock (TestSetRunListener .class );
@@ -134,17 +155,21 @@ public void testMergeTestHistoryResult() throws Exception {
134155 invokeMethod (factory , "mergeTestHistoryResult" );
135156 RunStatistics mergedStatistics = factory .getGlobalRunStatistics ();
136157
137- // Only TEST_THREE is a failing test, other three are flaky tests
138- assertEquals (5 , mergedStatistics .getCompletedCount ());
139- assertEquals (1 , mergedStatistics .getErrors ());
158+ // TEST_THREE and AlwaysFailClass.null are failing tests, regular tests + FlakyClass.null are flaky
159+ assertEquals (7 , mergedStatistics .getCompletedCount ());
160+ assertEquals (2 , mergedStatistics .getErrors ());
140161 assertEquals (0 , mergedStatistics .getFailures ());
141- assertEquals (3 , mergedStatistics .getFlakes ());
162+ assertEquals (4 , mergedStatistics .getFlakes ());
142163 assertEquals (0 , mergedStatistics .getSkipped ());
143164
144165 // Now test the result will be printed out correctly
145166 factory .printTestFailures (TestResultType .FLAKE );
146167 String [] expectedFlakeOutput = {
147168 "Flakes: " ,
169+ TEST_BEFORE_ALL_FLAKE + ".<beforeAll>" ,
170+ " Run 1: " + TEST_BEFORE_ALL_FLAKE + ".null " + TEST_ERROR_SUFFIX ,
171+ " Run 2: PASS" ,
172+ "" ,
148173 TEST_FOUR ,
149174 " Run 1: " + ASSERTION_FAIL ,
150175 " Run 2: PASS" ,
@@ -164,7 +189,16 @@ public void testMergeTestHistoryResult() throws Exception {
164189 reporter .reset ();
165190 factory .printTestFailures (TestResultType .ERROR );
166191 String [] expectedFailureOutput = {
167- "Errors: " , TEST_THREE , " Run 1: " + ASSERTION_FAIL , " Run 2: " + ERROR , " Run 3: " + ERROR , ""
192+ "Errors: " ,
193+ TEST_BEFORE_ALL_ERROR + ".<beforeAll>" ,
194+ " Run 1: " + TEST_BEFORE_ALL_ERROR + ".null " + TEST_ERROR_SUFFIX ,
195+ " Run 2: " + TEST_BEFORE_ALL_ERROR + ".null" ,
196+ "" ,
197+ TEST_THREE ,
198+ " Run 1: " + ASSERTION_FAIL ,
199+ " Run 2: " + ERROR ,
200+ " Run 3: " + ERROR ,
201+ ""
168202 };
169203 assertEquals (asList (expectedFailureOutput ), reporter .getMessages ());
170204
0 commit comments