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);
}
我正在使用的注释@Test是来自testng包而不是Junit。
改变那解决了我的问题。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句