Skip to content

Commit

Permalink
Improve Markdown of test failures.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Nov 21, 2023
1 parent 815b735 commit 01e0c81
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
17 changes: 14 additions & 3 deletions src/main/java/edu/hm/hafner/grading/TestMarkdown.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.util.function.Function;

import org.apache.commons.lang3.StringUtils;

import edu.hm.hafner.coverage.TestCase;

/**
Expand Down Expand Up @@ -89,13 +91,22 @@ else if (!stringBuilder.toString().endsWith(TRUNCATED_MESSAGE)) {
}

private String renderFailure(final TestCase issue) {
return String.format("<details>%n"
+ "<summary>%s:%s</summary>"
return String.format("__%s:%s__%n"
+ getMessage(issue)
+ "<details>%n"
+ "<summary>Stack Trace</summary>"
+ "%n%n"
+ "```text%n"
+ "%s%n"
+ "```"
+ "%n"
+ "</details>%n", issue.getClassName(), issue.getMessage(), issue.getDescription());
+ "</details>%n%n", issue.getClassName(), issue.getTestName(), issue.getDescription());
}

private String getMessage(final TestCase issue) {
if (issue.getMessage().isBlank()) {
return StringUtils.EMPTY;
}
return issue.getMessage() + "%n";
}
}
10 changes: 7 additions & 3 deletions src/test/java/edu/hm/hafner/grading/TestMarkdownTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,13 @@ void shouldShowScoreWithTwoResults() {
"|Modultests|0|0|10|-30",
"*:moneybag:*|*1*|*2*|*3*|*:ledger:*",
"*:moneybag:*|*-1*|*-2*|*-3*|*:ledger:*",
"<summary>test-class-failed-0:failed-message-0</summary>",
"<summary>test-class-failed-1:failed-message-1</summary>",
"<summary>test-class-failed-2:failed-message-2</summary>",
"__test-class-failed-0:test-failed-0__",
"__test-class-failed-1:test-failed-1__",
"__test-class-failed-2:test-failed-2__",
"failed-message-0",
"failed-message-1",
"failed-message-2",
"<summary>Stack Trace</summary>",
"```text\nStackTrace-0\n```",
"```text\nStackTrace-1\n```",
"```text\nStackTrace-2\n```")
Expand Down

0 comments on commit 01e0c81

Please sign in to comment.