Skip to content

Instantly share code, notes, and snippets.

@messeb
Created January 18, 2014 19:11
Show Gist options
  • Save messeb/8494805 to your computer and use it in GitHub Desktop.
Save messeb/8494805 to your computer and use it in GitHub Desktop.
UIViewControllers should also be tested. But tests for the connection of two controllers via Storyboard segues are often missing. Here a example how you can test segue from one to another UIViewController via -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender with OCMock.
UIViewController *vc = // ViewController
id mockVC = [OCMockObject partialMockForObject:vc];
UIButton *button = // Button on view of ViewController
UIStoryboardSegue *storyBoardSegue = [OCMArg checkWithBlock:^BOOL(id obj){
UIStoryboardSegue *segue = obj;
UIViewController *src = segue.sourceViewController;
UIViewController *dst = segue.destinationViewController;
NSString *idtf = segue.identifier;
bool isCorrectSrcController = [src isKindOfClass:[SRCViewController class]]; // replace type
bool isCorrectDstController = [dst isKindOfClass:[DSTViewController class]]; // replace type
bool isCorrectSegueIdentifier = [idtf isEqualToString:@"IDENTIFIER"]; // replace identifier
return isCorrectSrcController && isCorrectDstController && isCorrectSegueIdentifier;
}];
[[mockVC expect] prepareForSegue:storyBoardSegue sender:button];
// simulate button clock
[button sendActionsForControlEvents:UIControlEventTouchUpInside];
[mockVC verify];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment