I am trying to unit test an unwind segue.
But it seems that in the test calling performSegueWithIdentifier: method doesn't perform an unwind segue while it does for other kinds of segues, e.g. Push and Modal segues.
Basically what I am trying to do is the following:
- Get the view controller from storyboard.
Perform the unwind segue programmatically with this line of code:
[vc performSegueWithIdentifier:@"unwind" sender:vc];(I have tried to change the sender to
nilandvc.buttonwhich is the triggering button for the unwind segue. But the test still failed.)Check if the
seguePerformedproperty in the view controller is set to YES with this line of code:XCTAssertTrue(sut.seguePerfomed, @"should be true.");In this view controller's
- prepareForSegue:method, I am using the identifier of a segue to identify the unwind segue. If it is the unwind segue then set the view controller's seguePerformed property to YES.
I thought there was something wrong with my performSegue code.
However, if I copy this line [vc performSegueWithIdentifier:@"unwind" sender:vc]; into my view controller's viewDidAppear method to test it, and enter this view in an iPhone simulator. It does return to its previous view just after entering it.
Sorry that I forgot to mention that I also tried the following snippet:
- (void)testPerformingSegueShouldSetSeguePerform
{
// given
UINavigationController *nvVC = [sut.storyboard instantiateViewControllerWithIdentifier:@"nvVC"];
[nvVC pushViewController:sut animated:NO];
sut = (NTDSubViewController *)nvVC.topViewController;
// when
[sut performSegueWithIdentifier:@"unwind" sender:sut.button];
// then
XCTAssertTrue(sut.seguePerfomed, @"should be true.");
}
viewControllerscount changed, nor did thetopViewControllerchange. Even in the simulator, it takes more than a single unwind call to see these changes in the destination VC right away. Don't know what's missing though.Any luck on your side? - ctietze