我试图使用easyMock运行一个简单的测试:
public class Class1 implements Interface1{
public void method1(Object obj){
if(isEnable()){
doSmth();
}
}
public boolean isEnable(){
return isEnable;
}
}我的测试:
Interface1 test1= Interface1(Class1.class);
test1.method1(anyObject);
expectLastCall();
expect(test1.isEnable).andReturn(true);
replay(test1);
test1.method1(new Object());
verify(test1);错误:
验证预期失败: isEnable():预期: 1,实际:0
问题出在哪里?我已经阅读了大量的例子,在这些例子中,发送的参数都有类似的问题,但没有一个没有params example1或这个教程的方法,我发现这些问题很有趣。
提前感谢
发布于 2012-11-02 07:12:11
稍微修改一下模拟代码。您希望调用一个方法isEnable并返回true。
Interface1 test1= Interface1(Class1.class);
test1.method1(anyObject);
expectLastCall();
expect(test1.isEnable()).andReturn(true);
replay(test1);将实际测试更改为
test1.method1(new Object());
test1.isEnable();
verify(test1);https://stackoverflow.com/questions/13029679
复制相似问题