Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Tasks completed:
1. Locate ConsoleLauncher output
2. Check if actual and expected of AssertionFailedError are both type of CharSequence
To do list:
1. Add diff function dependency
2. Using diff to generate the output desired
  • Loading branch information
XuJ321 committed Aug 31, 2024
1 parent d85dd9b commit 107db04
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
import org.junit.platform.launcher.listeners.SummaryGeneratingListener;
import org.junit.platform.launcher.listeners.TestExecutionSummary;
import org.junit.platform.reporting.legacy.xml.LegacyXmlReportGeneratingListener;
//for console output of diff
import org.opentest4j.AssertionFailedError;
import org.opentest4j.ValueWrapper;

/**
* @since 1.0
Expand Down Expand Up @@ -180,11 +183,34 @@ private Optional<TestExecutionListener> createXmlWritingListener(PrintWriter out
private void printSummary(TestExecutionSummary summary, PrintWriter out) {
// Otherwise the failures have already been printed in detail
if (EnumSet.of(Details.NONE, Details.SUMMARY, Details.TREE).contains(outputOptions.getDetails())) {
//adding diff code here
summary.getFailures().forEach(failure -> {
//get AssertionFailedError
if(failure.getException() instanceof AssertionFailedError){
AssertionFailedError assertionFailedError = (AssertionFailedError)failure.getException();
ValueWrapper expected = assertionFailedError.getExpected();
ValueWrapper actual = assertionFailedError.getActual();
//apply diff function
if (isCharSequence(expected) && isCharSequence(actual)) {
out.printf("Expected %s\n", expected.getStringRepresentation());
out.printf("Actual %s\n", actual.getStringRepresentation());
//out.printf("Diff %s", calculateDiff(expected, actual));
}

}
});

summary.getFailures();
summary.printFailuresTo(out);
}
summary.printTo(out);
}

private boolean isCharSequence(ValueWrapper value) {
return value != null && CharSequence.class.isAssignableFrom(value.getType());
}


@FunctionalInterface
public interface Factory {
ConsoleTestExecutor create(TestDiscoveryOptions discoveryOptions, TestConsoleOutputOptions outputOptions);
Expand Down

1 comment on commit 107db04

@XJ114514
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the example image of running it
image

Please sign in to comment.