隨筆-295  評論-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ù)測 國富論
          posted on 2007-06-28 09:24 華夢行 閱讀(297) 評論(0)  編輯  收藏

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


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 保山市| 北票市| 正宁县| 龙陵县| 墨江| 河北区| 奇台县| 麻阳| 洪雅县| 巴林右旗| 灵寿县| 鹤山市| 黄浦区| 南岸区| 兰坪| 铁岭县| 岳阳市| 容城县| 浠水县| 江油市| 永清县| 绥芬河市| 汝城县| 临颍县| 海丰县| 龙岩市| 古丈县| 洪泽县| 黎城县| 静海县| 曲水县| 沙洋县| 娄烦县| 宁明县| 凉城县| 裕民县| 莲花县| 久治县| 正镶白旗| 元朗区| 昌邑市|