I thought I'd let you in on an observation we made, regarding where to place
context.assertIsSatisfied().
We are quite happily using jMock 2.4 and our tests typically look very
basic, like:
@Test
public void testOnNewCall() {
// Expectations
InitialState state = new InitialState(mockCdgContext);
context.checking(new Expectations() {
{
one(mockCdgContext).setState((NewState)
with(instanceOf(NewState.class)));
}
});
// Execute
state.onNewCallEvent(event);
// Verify
context.assertIsSatisfied();
}
We set up quite a lot of tests and everything worked fine. In a fit of
"over-do", we re-factored out the context.assertIsSatisfied() to a tear-down
method, like:
@After
public void tearDown() {
context.assertIsSatisfied();
}
Things still worked just dandy and we felt cool.
A few days later things got nasty. We added some more tests, but no longer
got any useful error messages in Eclipse. It most often just reported that
"
java.lang.AssertionError: not all expectations were satisfied" with the
corresponding stack trace pointing out what expectations that were never
invoked, but no clue to why. After a few hours of muttering and profanities,
we noted that we didn't have the same problem in some old classes where we
hadn't implemented the tear-down approach.
We put context.assertIsSatisfied() back into the test method and voilĂ ! We
got error messages like
"
java.lang.AssertionError: unexpected invocation:
Scenario.createNewState()", clearly pointing out the problem.
I don't know if this is a well known no-no, a bug or just stupid thinking on
our behalf. Just hoping to save you guys some hours of frustration.
Cheers,
/JMK
--
Sent from the jMock - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email