Created
January 18, 2014 19:11
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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