用例子说明:
有如下接口:
public interface MyTest {
int plus(int a, String... s);
}
这样mock这个接口就会报错:org.powermock.reflect.exceptions.MethodNotFoundException: No method found with name 'plus' with parameter types: [ java.lang.Integer ]
@Before
public void setUp2() throws Exception {
MyTest myTest = PowerMockito.mock(MyTest.class);
PowerMockito.spy(myTest);
PowerMockito.when(myTest, "plus", 1).thenReturn(2);
}
这样mock这个接口就对了:
@Before
public void setUp() throws Exception {
MyTest myTest = PowerMockito.mock(MyTest.class);
PowerMockito.spy(myTest);
PowerMockito.when(myTest, "plus", 1, "a").thenReturn(2);
}



