uipangesturerecognizer - iOS OCMock: How to test panning -
i new ocmock , needed getting started. have uiscrollview upon panning triggers event handler stuff. i'd test this. here's how make object
id gesturemock = [ocmockobject partialmockforobject:[uipangesturerecognizer new]];
now how set panning specifications?
after initializing panning, how "invoke" pan?
if testing code responds uipangesturerecognizer
, write test around target method of gesture recognizer.
// if have this... uipangesturerecognizer *pgr = [[uipangesturerecognizer alloc] initwithtarget:self action:@selector(didpan:)]; [self.scrollview addgesturerecognizer:pgr]; // this... - (void)didpan:(uipangesturerecognizer *)pgr { switch (pgr.state): { case uigesturerecognizerstateended: [self dosomething]; break; default: } } // id gesturemock = [ocmockobject mockforclass:[uipangesturerecognizer class]]; [[[gesturemock stub] andreturn:uipangesturerecognizerstateended] state]; id objectundertest = [ocmockobject partialmockforobject:[myclass new]]; [[objectundertest expect] dosomething]; // make call [objectundertest didpan:gesturemock]; [objectundertest verify];
Comments
Post a Comment