Skip to content

Commit 8b8a445

Browse files
committed
test: first show failed cases
1 parent f6d0e27 commit 8b8a445

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

integration-test/src/test/java/com/reajason/javaweb/MarkdownTestExecutionListener.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ public class MarkdownTestExecutionListener implements TestExecutionListener {
2727
private final Map<UniqueId, Instant> timeStamps = new HashMap<>();
2828
private Instant startTime;
2929
private final Path markdownPath = Paths.get("build", "test-results", "result.md");
30-
private final List<String> testResults = new ArrayList<>();
30+
private final List<String> passedResults = new ArrayList<>();
31+
private final List<String> failedResults = new ArrayList<>();
3132

3233
@SneakyThrows
3334
@Override
@@ -38,9 +39,6 @@ public void testPlanExecutionStarted(TestPlan testPlan) {
3839
startTime = Instant.now();
3940
lines.add("- Started At: " + startTime);
4041
Files.write(markdownPath, lines, StandardOpenOption.CREATE_NEW);
41-
42-
testResults.add("| **Image Name** | **Shell Type** | **Packer** | **Status**| **Duration(ms)** |");
43-
testResults.add("|----------------|----------------|------------|-----------|------------------|");
4442
}
4543

4644
@Override
@@ -51,7 +49,10 @@ public void testPlanExecutionFinished(TestPlan testPlan) {
5149
lines.add("- Finished At: " + endTime);
5250
lines.add("- Total Duration: " + Duration.between(startTime, endTime).getSeconds() + " seconds");
5351
lines.add("");
54-
lines.addAll(testResults);
52+
lines.add("| **Image Name** | **Shell Type** | **Packer** | **Status**| **Duration(ms)** |");
53+
lines.add("|----------------|----------------|------------|-----------|------------------|");
54+
lines.addAll(failedResults);
55+
lines.addAll(passedResults);
5556
Files.write(markdownPath, lines, StandardOpenOption.APPEND);
5657
}
5758

@@ -62,8 +63,11 @@ public void executionFinished(TestIdentifier testIdentifier, TestExecutionResult
6263
if (startTime != null) {
6364
String[] split = testIdentifier.getDisplayName().split("\\|");
6465
if (split.length == 3) {
65-
String status = testExecutionResult.getStatus().equals(TestExecutionResult.Status.SUCCESSFUL) ? "✔" : "✘";
66-
testResults.add("|" + split[0].trim() + "|" + split[1].trim() + "|" + split[2].trim() + "|" + status + "|" + Duration.between(startTime, Instant.now()).toMillis() + "|");
66+
if (testExecutionResult.getStatus().equals(TestExecutionResult.Status.SUCCESSFUL)) {
67+
passedResults.add("|" + split[0].trim() + "|" + split[1].trim() + "|" + split[2].trim() + "|✔|" + Duration.between(startTime, Instant.now()).toMillis() + "|");
68+
} else {
69+
failedResults.add("|" + split[0].trim() + "|" + split[1].trim() + "|" + split[2].trim() + "|✘|" + Duration.between(startTime, Instant.now()).toMillis() + "|");
70+
}
6771
}
6872
}
6973
}

0 commit comments

Comments
 (0)