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:

  1. assemble: build view controller , content array.
  2. act: call action method.
  3. 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

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -