posts - 165, comments - 198, trackbacks - 0, articles - 1
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理
          eclipse中如何寫一個測試私有方法的junit?
          假設類Summer定義如下:
          public class Summer{
          ???private int methodone(String argsone){
          ??????//method code
          ??????.......
          ??????return?4;
          ???}
          }

          測試如下:
          public class SummerTest extends TestCase {
          ???public void testMethodone(){
          ??????Object rightResult = xxxxx;
          ??????Summer?example =?new Summer.newInstance();
          ??????Method m =?example .getClass().getDeclaredMethod("methodone",new Class[]{String.class});
          ??????m.setAccessible(true);
          ??????Object result = m.invoke(example ,new?Object[]?{new String(xxxx)});
          ??????m.setAccessible(false);
          ??????if (result.equals(rightResult)){
          ?????????//your code
          ?????????......
          ??????}
          ???}
          }

          評論

          # re: 在Junit中測試私有函數的方法(junit, private, method) (轉)[未登錄]  回復  更多評論   

          2008-09-10 12:48 by zt
          Good!
          主站蜘蛛池模板: 两当县| 孝感市| 黔东| 南木林县| 高要市| 巧家县| 邮箱| 汪清县| 海林市| 阜城县| 灵台县| 临洮县| 陇西县| 长沙县| 石景山区| 贵南县| 怀宁县| 精河县| 塔河县| 盐池县| 锡林浩特市| 姜堰市| 公安县| 台江县| 论坛| 耿马| 霍州市| 基隆市| 图们市| 金乡县| 宣恩县| 沂南县| 哈尔滨市| 当涂县| 新沂市| 万荣县| 芒康县| 桂阳县| 星子县| 互助| 聊城市|