-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMiniTestRunner.java
More file actions
30 lines (29 loc) · 1.22 KB
/
Copy pathMiniTestRunner.java
File metadata and controls
30 lines (29 loc) · 1.22 KB
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
import java.lang.reflect.Method;
public class MiniTestRunner {
public static void main(String[] args) throws Exception {
int pass = 0, fail = 0;
for (String className : args) {
Class<?> clazz = Class.forName(className);
var ctor = clazz.getDeclaredConstructor();
ctor.setAccessible(true);
Object instance = ctor.newInstance();
for (Method m : clazz.getDeclaredMethods()) {
if (m.isAnnotationPresent(org.junit.jupiter.api.Test.class)) {
m.setAccessible(true);
try {
m.invoke(instance);
System.out.println(" PASS " + className + "#" + m.getName());
pass++;
} catch (Exception e) {
Throwable cause = e.getCause() != null ? e.getCause() : e;
System.out.println(" FAIL " + className + "#" + m.getName() + " -> " + cause);
fail++;
}
}
}
}
System.out.println();
System.out.println("Results: " + pass + " passed, " + fail + " failed");
if (fail > 0) System.exit(1);
}
}