|
36 | 36 | import org.junit.platform.launcher.listeners.SummaryGeneratingListener;
|
37 | 37 | import org.junit.platform.launcher.listeners.TestExecutionSummary;
|
38 | 38 | import org.junit.platform.reporting.legacy.xml.LegacyXmlReportGeneratingListener;
|
| 39 | +//for console output of diff |
| 40 | +import org.opentest4j.AssertionFailedError; |
| 41 | +import org.opentest4j.ValueWrapper; |
39 | 42 |
|
40 | 43 | /**
|
41 | 44 | * @since 1.0
|
@@ -180,11 +183,34 @@ private Optional<TestExecutionListener> createXmlWritingListener(PrintWriter out
|
180 | 183 | private void printSummary(TestExecutionSummary summary, PrintWriter out) {
|
181 | 184 | // Otherwise the failures have already been printed in detail
|
182 | 185 | if (EnumSet.of(Details.NONE, Details.SUMMARY, Details.TREE).contains(outputOptions.getDetails())) {
|
| 186 | + //adding diff code here |
| 187 | + summary.getFailures().forEach(failure -> { |
| 188 | + //get AssertionFailedError |
| 189 | + if(failure.getException() instanceof AssertionFailedError){ |
| 190 | + AssertionFailedError assertionFailedError = (AssertionFailedError)failure.getException(); |
| 191 | + ValueWrapper expected = assertionFailedError.getExpected(); |
| 192 | + ValueWrapper actual = assertionFailedError.getActual(); |
| 193 | + //apply diff function |
| 194 | + if (isCharSequence(expected) && isCharSequence(actual)) { |
| 195 | + out.printf("Expected %s\n", expected.getStringRepresentation()); |
| 196 | + out.printf("Actual %s\n", actual.getStringRepresentation()); |
| 197 | + //out.printf("Diff %s", calculateDiff(expected, actual)); |
| 198 | + } |
| 199 | + |
| 200 | + } |
| 201 | + }); |
| 202 | + |
| 203 | + summary.getFailures(); |
183 | 204 | summary.printFailuresTo(out);
|
184 | 205 | }
|
185 | 206 | summary.printTo(out);
|
186 | 207 | }
|
187 | 208 |
|
| 209 | + private boolean isCharSequence(ValueWrapper value) { |
| 210 | + return value != null && CharSequence.class.isAssignableFrom(value.getType()); |
| 211 | + } |
| 212 | + |
| 213 | + |
188 | 214 | @FunctionalInterface
|
189 | 215 | public interface Factory {
|
190 | 216 | ConsoleTestExecutor create(TestDiscoveryOptions discoveryOptions, TestConsoleOutputOptions outputOptions);
|
|
0 commit comments