【发布时间】:2021-06-30 09:39:41
【问题描述】:
运行以下代码时,我收到错误消息未完成的存根检测到:
这是带有 public static void myMethod 的 MyClass。
class MyClass{
public static void myMethod(){
return;
}
}
这是带有 myMethod2 方法的 MyClass2。在 myMethod2 内部,myMethod 正在调用。
class MyClass2{
public String myMethod2(){
MyClass.myMethod();
return "String";
}
}
这里是为测试 myMethod2 而编写的测试用例。
class MyMethodTest{
MyClass2 myClass2;
@Test
public void myMethodTwoTest(){
PowerMockito.mockStatic(MyClass.class);
PowerMockito.doNothing().when(MyClass.class);
MyClass.myMethod();
String str = myClass2.myMethod2();
assertEquals(str,"String");
}
}
运行此方法时,我收到 UnfinishedStubbingException。
org.mockito.exceptions.misusing.UnfinishedStubbingException:
Unfinished stubbing detected here:
-> at **.***.***.**.MyMethodTest.myMethodTwoTest(MyMethodTest.java:125)
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();```
Please help me to solve this issue.
【问题讨论】:
-
这些开发者都疯了
标签: java testing exception mockito powermockito