Reputation: 843
I'm trying to test an application based on storyboards. The scenario is a Navigation Controller with a View Controller inside. The test is that performing a segue sets a view controller as destination controller (push segue). I'm using OCMockito and here's my test:
MyViewController *mockSut = mock([MyViewController class]);
UINavigationController *nav = mock([UINavigationController class]);
[given(mockSut.navigationController) willReturn:nav];
[mockSut performSegueWithIdentifier:@"mySegue" sender:nil];
MKTArgumentCaptor *segueArgument = [[MKTArgumentCaptor alloc] init];
MKTArgumentCaptor *senderArgument = [[MKTArgumentCaptor alloc] init];
[verify(mockSut) prepareForSegue:[segueArgument capture] sender:[senderArgument capture]];
assertThat([[[segueArgument value] destinationViewController] class], equalTo([MyDestinationViewController class]));
But it complains that prepareForSegue:
method was not invoked.
What's the problem here? Maybe that performSegueWithIdentifier:
invokes prepareForSegue:
in an asynchronous way?
Upvotes: 1
Views: 165
Reputation: 20980
Who calls -prepareForSegue:sender:
? UIKit does. By trying to test that, you're testing UIKit — which is unnecessary. When dealing with a framework (that is, something that calls back to you), the basic pattern is:
Upvotes: 2