views:

80

answers:

1

Hello people. 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?

+1  A: 

It looks as if your verification is declared statically - once per test class, instead of once per test method.

Do this:

verify(mock, times(2)).did("my thing");

or in your case

verify(mockService, times(2)).getServices();

(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.)

Lunivore
In my case, it's a little different, the method I can verify isn't in a mock class.
joaosavio
Post your code then, please!
Lunivore