测试类
class testClass{
ClassUnderTest classUnderTest = new ClassUnderTest();
public class testmethod1(){
ClassNeedToMocked clasNeedToMocked=createNiceMock();
ExpectNew(ClassNeedToMocked).andReturn(class1).anytimes(); // have to mock from two methods
expect(classNeedToMocked.someMethod()).andReturn(returnvalue); // even return null while put .anyTimes()
replayAll(); // tried replay() and replayAll()
Map<> reponseMap=classUnderTest.method1();
}
}
正在测试的课程
ClassUnderTest{
public method1(){
ClassNeedToMocked classNeedToMocked = new ClassNeedToMocked();
Set<String> set = method2();
}
public method2(){
ClassNeedToMocked classNeedToMocked = new ClassNeedToMocked();
returnvalue = classNeedToMocked.smoeMethod(); // return Null here
return returnvalue;
}
}
上面的代码返回null,但是模拟的.expect().andReturn
无效。