Why does this TestNG test pass although the mock method is not invoked?
-
05-07-2021 - |
Question
I user TestNG and jMock for my unit test but, I have a problem with TestNG. It marks the test as passed when I expect mock object method to be invoked and it is not!
public class SomeTestTest {
Mockery mocker = new Mockery();
SomeInterface someInterface = mocker.mock(SomeInterface.class);
@Test
public void testName() throws Exception {
mocker.checking(new Expectations() {{
oneOf(someInterface).someMethod();
}});
}
}
and this is the report I get
Custom suite
Total tests run: 1, Failures: 0, Skips: 0
Solution
You're missing a call to Mockery.assertIsSatisfied()
.
That call tells jMock when you expect all expectations to be satisfied. Otherwise it wouldn't know at which point in your code you want those to be verified.
That's also explained in the Getting Started article.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow