java - Is there a way of having something like jUnit Assert message argument in Mockito's verify method? -
let's assume snippet of testing code:
observable model = class.forname(fullyqualifiedmethodname).newinstance(); observer view = mockito.mock(observer.class); model.addobserver(view); (method method : class.forname(fullyqualifiedmethodname).getdeclaredmethods()) { method.invoke(model, composeparams(method)); model.notifyobservers(); mockito.verify( view, mockito.atleastonce() ).update(mockito.<observable>any(), mockito.<object>any()); }
mockito.verify
method throws exception if method in model hasn't invoked observable.setchanged()
method.
problem: without adding loggers/system.print.out
can't realize what's current method has failed test. there way of having similar junit assert
methods:
assert.assertequals( string.format("instances %s, %s should equal", inst1, inst2), inst1.getparam(), inst2.getparam() );
solution:
verify(observer, new verificationmode() { @override public void verify(verificationdata data) { asserttrue( format( "method %s doesn't call observable#setchanged() after changing state of model", method.tostring() ), data.getallinvocations().size() > 0); } }).update(mockito.<observable>any(), mockito.<object>any());
this trick (simple , clear):
try { verify(mymockedobject, times(1)).dosomthing(); } catch (mockitoassertionerror e) { throw new mockitoassertionerror("was expecting call mymockedobject.dosomthing got "+ e.getmessage()); }
Comments
Post a Comment