我有一个在测试方法之外的以下方法。
但是当我调用这个方法时,我会得到以下错误。
private DynamicBuild getSkippedBuild() {
DynamicBuild build = mock(DynamicBuild.class);
when(build.isSkipped()).thenReturn(true);
return build;
}
但是当我调用这个方法时,我会得到以下错误。
org.mockito.exceptions.misusing.UnfinishedStubbingException:
Unfinished stubbing detected here:
-> at LINE BEING CALLED FROM
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();
Hints:
1. missing thenReturn()
2. you are trying to stub a final method, you naughty developer!
看起来 Mockito 不支持在测试方法之外进行存根。这是不被支持的吗?
编辑:我可以通过在 @Test
方法中进行存根来使其正常工作,但我想在多个 @Test
中重用这个存根。