JUnit testing: Difference between never() and times(0)
Asked Answered
N

1

9

I just want to know that what is the difference between times(0) and never() in JUnit testing.

For example I have the test line code for saving data in mongoDB:

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

if I write it as:

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

Both test shows that save method hasn't called. (correct me if I am wrong) Is there any difference between these two ?

Naphtha answered 3/12, 2012 at 7:34 Comment(0)
A
15

The javadoc of the never method says: Alias to times(0), see Mockito.times(int). So never() is just a shortcut for times(0).

Association answered 3/12, 2012 at 8:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.