【发布时间】:2021-04-06 05:06:00
【问题描述】:
我正在尝试使用 PowerMockito 模拟静态方法,我尝试了一些选项来模拟一个类,导致不同的异常。
@RunWith(PowerMockRunner.class)
@PrepareForTest({Base64.class})
public class BqClientFactoryTest {
@Test
public void testGetBigQueryClient() throws Exception {
mockStatic(Base64.class);
Base64.Decoder mockDecoder = mock(Base64.Decoder.class);
when(Base64.getDecoder()).thenReturn(mockDecoder);
这导致org.mockito.exceptions.misusing.MissingMethodInvocationException:
我用了另一个这样的例子
@RunWith(PowerMockRunner.class)
@PrepareForTest({Base64.class})
public class BqClientFactoryTest {
@Test
public void testGetBigQueryClient() throws Exception {
mockStatic(Base64.class);
Base64.Decoder mockDecoder = mock(Base64.Decoder.class);
doReturn(mockDecoder).when(Base64.class, "getDecoder");
这给了我
org.mockito.exceptions.misusing.UnfinishedStubbingException:
Unfinished stubbing detected here:
如果我使用
BDDMockito.given(Base64.getDecoder()).willReturn(mockDecoder);
从 Mocking static methods with Mockito ,它仍然返回 org.mockito.exceptions.misusing.MissingMethodInvocationException
我试图检查关于 SO 的类似问题,但它们似乎没有帮助。 任何解决此问题的帮助表示赞赏。
【问题讨论】:
标签: powermockito