-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRunTests.java
More file actions
30 lines (25 loc) · 800 Bytes
/
Copy pathRunTests.java
File metadata and controls
30 lines (25 loc) · 800 Bytes
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
package effect.java.annotation.item39;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class RunTests {
public static void main(String[] args) throws Exception {
int tests = 0;
int passed = 0;
Class<?> testClass = Class.forName("effect.java.annotation.item39.Sample");
for (Method m: testClass.getDeclaredMethods()) {
if(m.isAnnotationPresent(Test.class)) {
tests ++;
try {
m.invoke(null);
passed++;
} catch (InvocationTargetException wrappedExc) {
Throwable exc = wrappedExc.getCause();
System.out.println(m + " failed: " + exc);
} catch (Exception exc) {
System.out.println("Invalid @Test: " + m);
}
}
}
System.out.printf("Passed: %d, Failed: %d%n", passed, tests - passed);
}
}