-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
ColoredPrintingTestListener.java
97 lines (80 loc) · 2.91 KB
/
ColoredPrintingTestListener.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package org.junit.gen5.console;
import org.junit.gen5.engine.TestDescriptor;
import org.junit.gen5.engine.TestExecutionListener;
import org.junit.gen5.engine.TestPlanExecutionListener;
import java.io.PrintStream;
/**
* @author Stefan Bechtold
* @since 5.0
*/
public class ColoredPrintingTestListener implements TestPlanExecutionListener, TestExecutionListener {
public static final String ANSI_RESET = "\u001B[0m";
public static final String ANSI_BLACK = "\u001B[30m";
public static final String ANSI_RED = "\u001B[31m";
public static final String ANSI_GREEN = "\u001B[32m";
public static final String ANSI_YELLOW = "\u001B[33m";
public static final String ANSI_BLUE = "\u001B[34m";
public static final String ANSI_PURPLE = "\u001B[35m";
public static final String ANSI_CYAN = "\u001B[36m";
public static final String ANSI_WHITE = "\u001B[37m";
private final PrintStream out;
public ColoredPrintingTestListener(PrintStream out) {
this.out = out;
}
@Override
public void testPlanExecutionStarted(int numberOfStaticTests) {
out.printf("Test execution started. Number of static tests: %d%n", numberOfStaticTests);
}
@Override
public void testPlanExecutionPaused() {
out.println("Test execution paused.");
}
@Override
public void testPlanExecutionRestarted() {
out.println("Test execution continued.");
}
@Override
public void testPlanExecutionStopped() {
out.println("Test execution canceled.");
}
@Override
public void testPlanExecutionFinished() {
out.println(ANSI_RESET);
}
@Override
public void dynamicTestFound(TestDescriptor testDescriptor) {
out.print(ANSI_GREEN);
out.format("Test found: %s", testDescriptor.toString());
out.println(ANSI_RESET);
}
@Override
public void testStarted(TestDescriptor testDescriptor) {
out.print(ANSI_GREEN);
out.format("Test started: %s", testDescriptor.toString());
out.println(ANSI_RESET);
}
@Override
public void testSkipped(TestDescriptor testDescriptor, Throwable t) {
out.print(ANSI_YELLOW);
out.format("Test skipped: %s\n=> Exception: %s", testDescriptor.toString(), (t != null) ? t.getLocalizedMessage() : "none");
out.println(ANSI_RESET);
}
@Override
public void testAborted(TestDescriptor testDescriptor, Throwable t) {
out.print(ANSI_YELLOW);
out.format("Test aborted: %s\n=> Exception: %s", testDescriptor.toString(), (t != null) ? t.getLocalizedMessage() : "none");
out.println(ANSI_RESET);
}
@Override
public void testFailed(TestDescriptor testDescriptor, Throwable t) {
out.print(ANSI_RED);
out.format("Test failed: %s\n=> Exception: %s", testDescriptor.toString(), t.getLocalizedMessage());
out.println(ANSI_RESET);
}
@Override
public void testSucceeded(TestDescriptor testDescriptor) {
out.print(ANSI_GREEN);
out.format("Test succeeded: %s", testDescriptor.toString());
out.println(ANSI_RESET);
}
}