Is there any way in JMock2 to let a test pass when reaching the execution of a given mock's method call? In other words, I would like to write some test code like:
assertTrue(when(aRequestMock).methodCall());
To test production code like:
public void methodUnderTest(){
// Some initialization code and members call
request.foo();
String a = anotherInstance.bar();
// many more calls to follow
}
...so I would not need to mock 'anotherInstance.bar()' return value as well as any other mock call to follow?
I know that it would not represent any strict check and it cannot be considered a best practice, yet it would come handy when testing methods with a long list of members' methods.
Given code:
you cannot skip the execution of
bar()andbaz()oncefoo()is invoked. Let me also say that you don't want to do that, because even if you could skip it in the test, it's going to be executed in production anyway, so you'd better test it, too :-)The nearest thing you can do is
Here I'm using
oneOf()on the first line becausefoo()is the focus of your test. You can also simplify this by not mentioningbar()andbaz():However, keep in mind that by doing so you will ignore any method invocation on
anInstanceMockandyetAnotherInstanceMock.