【发布时间】:2017-09-29 20:43:44
【问题描述】:
我有一个有两个私有方法的类,我正在为一个方法 test() 编写 JUnit,并希望另一个方法 test1 什么都不做。就像这样..我要调用的方法是 test(),当它被称为 test1() 时我想要它什么都不做
class foo{
private void test1() {
//some code;
}
private int test( Element e){
test1(element e);
return 0;
}
}
我的测试课是这样的……
@RunWith(PowerMockRunner.class)
@PrepareForTest(Foo.class)
public class FooTest {
private Foo foo= new Foo;
public void testTest() {
element e;
Foo testOb= PowerMockito.spy(foo);
PowerMockito.doNothing().when(testOb, "test1", Matchers.any(Element.class));
PowerMockito.doCallRealMethod().when(testOb, "test", e);
}
现在我面临的问题是它显示异常
org.mockito.exceptions.misusing.UnfinishedStubbingException:
Unfinished stubbing detected here:
-> at org.powermock.api.mockito.internal.PowerMockitoCore.doAnswer(PowerMockitoCore.java)
E.g. thenReturn() may be missing.
Examples of correct stubbing:
when(mock.isOk()).thenReturn(true);
when(mock.isOk()).thenThrow(exception);
doThrow(exception).when(mock).someVoidMethod();
now if i remove the "PowerMockito.doNothing().when(testOb, "test1", Matchers.any(Element.class));" line then it works fine but adding this produces the exception can anyone please help me..
【问题讨论】:
标签: java unit-testing exception powermockito private-methods