如何在Junit 5中检查模拟的对象是否有空状态?
如果我有一个在服务层中的对象,
@Autowired
private Config appConfig;
.
.
.
if(appConfig == null)
//check configuration
则通过模拟对象编写的junit。
@Mock
private Config appConfig;
如何使该对象在JUNIT中为Nult以涵盖测试案例中的条件?
If I have an object as below in service layer
@Autowired
private Config appConfig;
.
.
.
if(appConfig == null)
//check configuration
JUnit written by mocking the object.
@Mock
private Config appConfig;
How to make that object to null in JUnit to cover that condition in test case?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以做类似的事情:
这将显示
null
作为输出。You can do something like :
This displays
null
as output.对于
null
,您根本不需要模拟。为什么不只是将null
值传递到测试方法中,而不是appconfig
字段?For
null
you don't need a mock at all. Why don't you just pass in thenull
value into the method to test, instead of yourappConfig
field?