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
| import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
public class TestRunner {
public static final String RED = "\033[31;1m";
public static final String GREEN = "\033[32;1m";
public static final String RESET = "\033[0m";
public static void main(String[] args) {
Result result = JUnitCore.runClasses(MyClassToTest.class);
System.out.print("Ran " + result.getRunCount() + ", ");
System.out.print("ignored " + result.getIgnoreCount() + ", ");
System.out.print("in " + result.getRunTime() + " ms.");
int fails = result.getFailureCount();
String color = (fails == 0 ? GREEN : RED);
System.out.println(" " + color + result.getFailureCount() + " failed." +
RESET);
if (result.wasSuccessful()) {
System.out.println(GREEN + "✓ All tests passed." + RESET);
} else {
for (Failure failure : result.getFailures()) {
System.out.println(RED + "𝘹 " + failure.toString() + "\033[0m");
}
}
}
}
|