隨筆-295  評(píng)論-26  文章-1  trackbacks-0

          ? 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 {
          ???
          ???
          ???
          }



          大盤預(yù)測(cè) 國(guó)富論
          posted on 2007-06-28 09:24 華夢(mèng)行 閱讀(303) 評(píng)論(0)  編輯  收藏

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 临朐县| 右玉县| 化州市| 太白县| 同心县| 永济市| 林州市| 临潭县| 黄大仙区| 汕尾市| 封开县| 宁明县| 云阳县| 琼海市| 上饶市| 中阳县| 石林| 商洛市| 封丘县| 北宁市| 襄垣县| 思茅市| 义乌市| 苗栗市| 江永县| 广灵县| 鹤山市| 如东县| 灵川县| 大厂| 梁山县| 横山县| 保德县| 湖口县| 澄江县| 山阳县| 新宾| 城步| 平凉市| 云龙县| 甘孜县|