【问题标题】:JUnit, TestNg and Mockito Null Pointer ExceptionJUnit、TestNg 和 Mockito 空指针异常
【发布时间】: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);
    }

【问题讨论】:

    标签: junit mockito testng


    【解决方案1】:

    我使用的注解 @Test 来自 testng 包而不是 Junit。

    更改解决了我的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-19
      • 2021-06-15
      • 2021-06-30
      • 1970-01-01
      • 1970-01-01
      • 2015-10-07
      • 1970-01-01
      • 2019-04-09
      相关资源
      最近更新 更多