【发布时间】:2019-05-24 15:56:05
【问题描述】:
org.mockito 的注解 @Spy 和 @Mock 在我的 junit 测试类中不起作用。
上面的代码抛出了一个空指针异常。
例如:
@RunWith(MockitoJUnitRunner.class)
public class XServiceImplTest {
@Spy
private XServiceImpl xService;
@Test
public void testGenererPdf() throws Exception {
xService.anyCall();
}
}
添加此代码后,测试正常
@Before
public void init() {
MockitoAnnotations.initMocks(this);
}
【问题讨论】: