Intellij Debug Mockito模拟(接口)测试-NullPoInterException
测试类代码:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论