Intellij Debug Mockito模拟(接口)测试-NullPoInterException

发布于 2025-02-13 11:01:20 字数 635 浏览 1 评论 0原文

测试类代码:

when(sqlSession.getMapper(ArgumentMatchers.eq(AlertSignalMstMapper.class))).thenReturn(alertSignalMstMapper);

此处AlertSignalMstMapper是一个接口。

当我进行MVN测试时 测试通过。

但是,当我使用Intellij的调试时,我会在实际类(而不是测试方法中)中的null:

 List<AlertSignalMst> alertSigMsts = sqlSession.getMapper(AlertSignalMstMapper.class).getMstCodes();

sqlsession.getMapper(alertsignalmstmapper.class)返回artuall类中的null。

此行返回木星测试类(import org.junit.jupiter.api.test; )用于代替导入org.junit.test;

不确定这是Intellij问题,还是我没有正确设置Mockito。我正在使用Java17,Maven,Spring Boot,Mockito 4.5,Junit 4.13.2

Test class code:

when(sqlSession.getMapper(ArgumentMatchers.eq(AlertSignalMstMapper.class))).thenReturn(alertSignalMstMapper);

Here AlertSignalMstMapper is an interface.

When I do >mvn test
the tests passes.

But when I used debug of Intellij I get null on the actual class (And not in test method):

 List<AlertSignalMst> alertSigMsts = sqlSession.getMapper(AlertSignalMstMapper.class).getMstCodes();

Here sqlSession.getMapper(AlertSignalMstMapper.class) returns null on actuall class to be tested.

This line returns the mock object when the jupiter Test class (import org.junit.jupiter.api.Test;
) is used instead of import org.junit.Test;

Not sure if this is an intellij issue or I am not setting mockito correctly. I am usingh Java17, maven, Spring boot, Mockito 4.5, Junit 4.13.2

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文