문제

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:

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top