7
7
import org .junit .platform .engine .UniqueId ;
8
8
import org .junit .platform .engine .reporting .ReportEntry ;
9
9
import org .junit .platform .launcher .TestExecutionListener ;
10
+ import org .junit .platform .launcher .TestIdentifier ;
10
11
import org .junit .platform .launcher .listeners .TestExecutionSummary ;
11
12
import org .pitest .mutationtest .tooling .CombinedStatistics ;
12
13
13
14
import javax .tools .Diagnostic ;
14
15
import javax .tools .JavaFileObject ;
15
16
import java .io .*;
16
17
import java .time .LocalDateTime ;
17
- import java .util .InputMismatchException ;
18
- import java .util .List ;
19
- import java .util .Set ;
18
+ import java .util .*;
20
19
21
20
import static javax .tools .Diagnostic .Kind .ERROR ;
22
21
@@ -25,28 +24,7 @@ public class ResultBuilder {
25
24
private boolean failed ;
26
25
private StringBuilder result = new StringBuilder ();
27
26
private StringBuilder debug = new StringBuilder ();
28
- private StringBuilder consoleOutput = new StringBuilder ();
29
- private OutputStream outputStream ;
30
- private PrintStream console ;
31
-
32
- public ResultBuilder () {
33
- this .console = System .out ;
34
-
35
- this .outputStream = new OutputStream () {
36
- @ Override
37
- public void write (int b ) throws IOException {
38
- consoleOutput .append ((char )b );
39
- }
40
- };
41
- }
42
-
43
- public void startCapturingConsole () {
44
- System .setOut (new PrintStream (this .outputStream ));
45
- }
46
-
47
- public void stopCapturingConsole () {
48
- System .setOut (this .console );
49
- }
27
+ private Map <TestIdentifier , ReportEntry > additionalReports = new HashMap <>();
50
28
51
29
public void compilationFail (List <Diagnostic <? extends JavaFileObject >> diagnostics ) {
52
30
l ("We could not compile your code. See the compilation errors below:" );
@@ -120,23 +98,32 @@ public void logJUnitRun(TestExecutionSummary summary) {
120
98
failed ();
121
99
}
122
100
101
+ public void logAdditionalReport (TestIdentifier testIdentifier , ReportEntry report ) {
102
+ this .additionalReports .put (testIdentifier , report );
103
+ }
104
+
123
105
private void logJUnitFailedTest (TestExecutionSummary .Failure failure ) {
124
106
UniqueId .Segment lastSegment = failure .getTestIdentifier ().getUniqueIdObject ().getLastSegment ();
125
107
126
108
switch (lastSegment .getType ()) {
127
109
case "test-template-invocation" -> {
128
110
String methodName = this .getParameterizedMethodName (failure );
129
111
l (String .format ("\n - Parameterized test \" %s\" , test case %s failed:" , methodName , lastSegment .getValue ()));
112
+ l (String .format ("%s" , failure .getException ()));
130
113
}
131
114
case "property" -> {
132
- l (String .format ("\n - Property test \" %s\" failed (see full output below for more info):" , failure .getTestIdentifier ().getDisplayName ()));
115
+ l (String .format ("\n - Property test \" %s\" failed:" , failure .getTestIdentifier ().getDisplayName ()));
116
+ l (String .format ("%s" , failure .getException ()));
117
+
118
+ if (this .additionalReports .containsKey (failure .getTestIdentifier ())) {
119
+ l (this .additionalReports .get (failure .getTestIdentifier ()).getKeyValuePairs ().toString ());
120
+ }
133
121
}
134
122
default -> {
135
123
l (String .format ("\n - Test \" %s\" failed:" , failure .getTestIdentifier ().getDisplayName ()));
124
+ l (String .format ("%s" , failure .getException ()));
136
125
}
137
126
}
138
-
139
- l (String .format ("%s" , failure .getException ()));
140
127
}
141
128
142
129
private String getParameterizedMethodName (TestExecutionSummary .Failure failure ) {
@@ -153,7 +140,7 @@ public String buildEndUserResult() {
153
140
}
154
141
155
142
public String buildDebugResult () {
156
- return debug .toString () + "\n \n " + result .toString () + " \n \n \n \n \n " + this . consoleOutput . toString () ;
143
+ return debug .toString () + "\n \n " + result .toString ();
157
144
}
158
145
159
146
0 commit comments