iphone - Unit test in IOS -
i have uibutton in app. when click button, removes last object in nsmutablearray. this, want write unit tests.please 1 give me suggestion.
i use code knowing when click on uibutton performed:
[viewcontrollerobject.backbutton1 sendactionsforcontrolevents:uicontroleventtouchupinside];
thanks, ricky.
at "unit" level there 2 things you're testing:
- does tapping button send action method?
- does action method remove last object array?
ignore first one, that's apple's problem (or charitably it's integration test). second straightforward if think assemble, act, assert process:
- assemble: build view controller , content array.
- act: call action method.
- assert: check last object removed.
-(void)testremovaloflastobjectonbuttonaction { //... build , populate view controller id lastobject = [array lastobject]; [viewcontroller buttontapped: sender]; stassertfalse([array containsobject: lastobject], @"object %@ should removed", lastobject); }
note test explicitly whether last object removed, not whether count decremented: happen if any object removed.
Comments
Post a Comment