0
請幫幫忙,這個模擬是不工作:無法通過嘲弄一個jmockit私有方法
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();
}