Junit中测试私有函数的方法
2012-09-27 09:29
363 查看
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 = 4;
Summer example = new Summer();
Method m = example .getClass().getDeclaredMethod("methodone",new Class[]{String.class});
m.setAccessible(true);
Object result = m.invoke(example ,new Object[] {new String("a")});
m.setAccessible(false);
if (result.equals(rightResult)){
//your code
......
}
}
}
假设类Summer定义如下:
public class Summer{
private int methodone(String argsone){
//method code
.......
return 4;
}
}
测试如下:
public class SummerTest extends TestCase {
public void testMethodone(){
Object rightResult = 4;
Summer example = new Summer();
Method m = example .getClass().getDeclaredMethod("methodone",new Class[]{String.class});
m.setAccessible(true);
Object result = m.invoke(example ,new Object[] {new String("a")});
m.setAccessible(false);
if (result.equals(rightResult)){
//your code
......
}
}
}
相关文章推荐
- [JAVA]在Junit中测试私有函数的方法(junit, private, method)
- Junit中对私有方法测试
- junit 测试私有方法或私有变量
- Junit测试私有方法
- java反射运用举例-junit测试私有方法
- Junit3.8 私有方法测试
- Junit3.8 私有方法测试
- JUnit单元测试(五)--通过反射测试私有方法
- JUnit 3.8 通过反射测试私有方法
- Junit 测试私有方法和私有变量方法
- 使用Junit 测试私有方法
- JUnit 3.8 通过反射测试私有方法
- JUnit 3.8 通过反射测试私有方法
- JUnit 3.8 通过反射测试私有方法
- junit私有方法测试
- JUnit 3.8 通过反射测试私有方法
- [Junit] 测试方法执行顺序
- IDEA 安装 junit 测 b7da 试插件,生成测试方法
- junit测试延伸--方法的重复测试
- 在一个Objective-c的类里定义私有函数的方法