Skip to content

Commit

Permalink
Issue: junit-team#3139 Add number reference to each test
Browse files Browse the repository at this point in the history
  • Loading branch information
XJ114514 committed Oct 25, 2024
1 parent de00ade commit a3f8f25
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public DiffPrinter(TestPlan testPlan) {

//print the difference of two print to out
void printDiff(PrintWriter out, String expected, String actual, TestIdentifier testIdentifier) {
out.printf(" %s:", describeTest(testIdentifier));
char id = testIdentifier.getUniqueId().charAt(testIdentifier.getUniqueId().length() - 4);
out.printf(" (%c) %s:", id == 's' ? '1' : id, describeTest(testIdentifier));
boolean inlineDiffByWordFlag = false;
if (expected.contains(" ") || actual.contains(" ")) {
inlineDiffByWordFlag = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ public void printFailuresTo(PrintWriter writer, int maxStackTraceLines) {
if (getTotalFailureCount() > 0) {
writer.printf("%nFailures (%d):%n", getTotalFailureCount());
this.failures.forEach(failure -> {
writer.printf("%s%s%n", TAB, describeTest(failure.getTestIdentifier()));
writer.printf("%s(%c) %s%n", TAB, getTestId(failure.getTestIdentifier()),
describeTest(failure.getTestIdentifier()));
printSource(writer, failure.getTestIdentifier());
writer.printf("%s=> %s%n", DOUBLE_TAB, failure.getException());
printStackTrace(writer, failure.getException(), maxStackTraceLines);
Expand All @@ -223,6 +224,12 @@ private String describeTest(TestIdentifier testIdentifier) {
return join(":", descriptionParts);
}

//return the unique id of the test
private char getTestId(TestIdentifier testIdentifier) {
char id = testIdentifier.getUniqueId().charAt(testIdentifier.getUniqueId().length() - 4);
return id == 's' ? '1' : id;
}

private void collectTestDescription(TestIdentifier identifier, List<String> descriptionParts) {
descriptionParts.add(0, identifier.getDisplayName());
this.testPlan.getParent(identifier).ifPresent(parent -> collectTestDescription(parent, descriptionParts));
Expand Down

0 comments on commit a3f8f25

Please sign in to comment.