ios - OCMock test category methods -
i may not understand mocking have burning question basic scenario. how 1 test instance method of class or how 1 test category method class?
consider class peermessage
defines few properties, etc. create own custom category peermessage
called type
define method, istextmessage:
. istextmessage
returns boolean value based on contents of peermessage
. (please not sample type.)
in test ocmock, configure mock of type peermessage
, set it's content valid value follows:
id peermessage = [ocmockobject mockforclass:[peermessage class]]; [[[peermessage stub] andreturn:@"<valid>"] content];
and assert peermessage text message:
xctassert([peermessage istextmessage]);
considering how mocking works, results in: 'unexpected method invoked'. clearly, didn't specify expecting it; neither did stub it. wanted verify api.
how 1 test these instance methods (in case, category instance methods). 1 way redesign category follows:
instead of
- (bool)istextmessage;
do:
+ (bool)istextmessage:(peermessage *)message;
but me unnatural , don't feel writing code although don't see wrong it. doesn't need class method. :/
(if explanation question bit ambiguous, i'd happy update.)
you want use partial mock, somehow this:
id peermessage = [ocmockobject partialmockforobject:[[peermessage alloc] init]]; [[[peermessage stub] andreturn:@"<valid>"] content]; xctassert([peermessage istextmessage]);
this way, real implementation of istextmessage
, 1 want test, invoked, can still stub out other methods on object.
Comments
Post a Comment