PowerMock:来自父类的存根方法
2022-09-01 21:24:26
我正在使用PowerMock,我想知道如何保留子类的所有行为,但存根调用可能会被子类覆盖。super
假设我有这门课:
public class A {
public String someMethod() {
return "I don't want to see this value";
}
}
和一个子类:
public class B extends A {
@Override
public String someMethod() {
return super.someMethod() + ", but I want to see this one";
}
}
如何将调用存根到 ?super.someMethod()
我试过了
@Test
public void test() {
B spy = PowerMockito.spy(new B());
PowerMockito.doReturn("value").when((A)spy).someMethod();
assertEquals("value, but I want to see this one", spi.someMethod());
}