? import java.lang.reflect.*;
public class RunTest {
??? public static void main(String[] args) throws Exception {
???????
??????? int passed = 0, failed = 0;
??????? for (Method m : Class.forName("Foo").getMethods()) {
??????????? if (m.isAnnotationPresent(Test.class)) {
??????????????? try {
??????????????????? m.invoke(null);
???????????????????
??????????????????? passed++;
??????????????? } catch (Throwable ex) {
??????????????????? System.out.printf("Test %s failed: %s %n", m, ex.getCause());
??????????????????? failed++;
??????????????? }
??????????? }
??????? }
??????? System.out.printf("Passed: %d, Failed %d%n", passed, failed);
??? }
}
public class Foo {
??? @Test public static void m1() {
??? System.out.println("m1 SUcsessful");
??? }
??? public static void m2() { }
??? @Test public static void m3() {
??????? System.out.println("m3 Fails");
??????? throw new RuntimeException("Boom");
??? }
??? public static void m4() { }
??? @Test public static void m5() { }
??? public static void m6() { }
??? @Test public static void m7() {
??????? throw new RuntimeException("Crash");??????? }
???
??? public static void m8() { }
}
import java.lang.annotation.*;
/*
?* Test.java
?*
?* Created on 2007年6月28日, 上午8:52
?*
?* To change this template, choose Tools | Template Manager
?* and open the template in the editor.
?*/
/**
?*
?* @author ljl
?*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Test {
???
???
???
}
大盤預測
國富論
posted on 2007-06-28 09:24
華夢行 閱讀(297)
評論(0) 編輯 收藏