我是靠谱客的博主 从容乐曲,这篇文章主要介绍[JAVA]在Junit中测试私有函数的方法(junit, private, method),现在分享给大家,希望可以做个参考。

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
         ......
      }
   }
}

最后

以上就是从容乐曲最近收集整理的关于[JAVA]在Junit中测试私有函数的方法(junit, private, method)的全部内容,更多相关[JAVA]在Junit中测试私有函数的方法(junit,内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(98)

评论列表共有 0 条评论

立即
投稿
返回
顶部