无法通过JMockJava方法对其进行模拟
请帮助,此模拟不起作用:
class ClassBeingTested {
private AnotherClass anotherClass;
public void someMethod() {
int ans = anotherClass.targetMethod(5);
// Use ans here
}
}
//我的测试
ClassBeingTested classObject;
AnotherClass anotherClassObject;
@Before
public void setup() {
// Initialize anotherClassObject here
classObject = new ClassBeingTested(anotherClassObject);
new NonStrictExpectations(anotherClassObject) {{
invoke(anotherClassObject, "targetMethod", Integer.class); result = 100;
}};
}
@Test
public void testSomeMethod() {
classObject.someMethod();
}
# 1 楼答案
用JMockit这种嘲弄方式怎么样
# 2 楼答案
我一替换Integer,模拟就起作用了。使用实际期望的int值初始化