我对 JUnit 测试一种方法有疑问。我使用 EasyMock.createMock 来模拟 someDao。我仍然得到easymock unexpected method call expected 1 actual 0 someDato.findByCriteria(criteria, -1, -1)
这就是代码的样子(它只是草稿)。我怀疑问题出在criteria
对象上。错误点线return someDato.findByCriteria(criteria, -1, -1);
@Test
public void findDataSericeTest(){
DetachedCriteria criteria = DetachedCriteria.forClass(SomeClass.class);
criteria.add(Restictions.eq("sth1",string1));
criteria.add(Restictions.eq("sth2",string2));
expect(someDato.findByCriteria(criteria, -1, -1)).andReturn(SomeClass);
replay(someDao);
serviceTested.findDataService("string1","string2");
EasyMock.verify(someDao);
}
public SomeClass findDataService(String string1, String string2){
DetachedCriteria criteria = DetachedCriteria.forClass(SomeClass.class);
criteria.add(Restictions.eq("sth1",string1));
criteria.add(Restictions.eq("sth2",string2));
return someDato.findByCriteria(criteria, -1, -1);
}
有任何想法吗?