Java PowerMock-存根父方法调用不会返回存根值
两个班。父对象:B。子对象:A.A.method1()覆盖BJava PowerMock-存根父方法调用不会返回存根值,java,junit,powermock,stubbing,Java,Junit,Powermock,Stubbing,两个班。父对象:B。子对象:A.A.method1()覆盖B public class B { protected boolean method1(){...}; } public class A extends B { protected boolean method1(){ boolean val = super.method1(); ... //very short segment of logic that doesn't affect
public class B {
protected boolean method1(){...};
}
public class A extends B {
protected boolean method1(){
boolean val = super.method1();
... //very short segment of logic that doesn't affect val.
return val;
}
}
在我的测试类中:
@Test
public void testA() {
stub(method(B.class, "method1")).toReturn(true);
assertTrue((Boolean)(Whitebox.invokeMethod(A.class, "method1")));
}
断言失败(返回false)。我错过什么了吗?提前谢谢你的帮助 您测试的方法是非静态方法。我认为,您只能为模拟实例存根非静态方法。因此,无法传递用于存根的类对象