When I put a “VerificationModeFactory.times(2)” in test before, when I run all tests of the class appears this exception:
org.mockito.exceptions.verification.WantedButNotInvoked:
Wanted but not invoked:
serviceService.getServices();
If I run each test separately or remove “VerificationModeFactory.times(2)” all works.
It’s very weird. Could anybody help me?
It looks as if your verification is declared statically – once per test class, instead of once per test method.
Do this:
or in your case
(BTW, is it important that your class gets the service twice, or is it more important that it used it? Unless you’re describing a performance fix, I’d probably concentrate on the value the service provides instead. Using Mockito that way helps keep tests flexible. My 2 cents.)