我只想知道JUnit测试中times(0)和never()之间有什么区别。
例如,我有用于将数据保存在mongoDB中的测试行代码:
verify(mockRepository,never()).save(any(User.class));
如果我将其写为:
verify(mockRepository,times(0)).save(any(User.class));
两项测试均表明未调用save方法。 (如果我错了,请纠正我)
两者之间有什么区别吗?
最佳答案
javadoc of the never method说:Alias to times(0), see Mockito.times(int)
。因此,never()
只是times(0)
的快捷方式。
关于unit-testing - JUnit测试: Difference between never() and times(0),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13678976/