JUnit test: difference between never () and times (0)

I just want to know that the difference between times (0) and never () is in JUnit testing. For example, I have a test string code to save data in mongoDB:

verify(mockRepository,never()).save(any(User.class)); 

if I write it like:

 verify(mockRepository,times(0)).save(any(User.class)); 

Both tests show that the save method did not call. (correct me if I am wrong) Is there a difference between the two?

Thanks and respect,

+4
source share
1 answer

javadoc never works : Alias to times(0), see Mockito.times(int) . Thus, never() is just a shortcut to times(0) .

+5
source

All Articles