Ios 一种测试prepareForSegue是否执行其功能的方法';应该是的

Ios 一种测试prepareForSegue是否执行其功能的方法';应该是的,ios,objective-c,unit-testing,storyboard,Ios,Objective C,Unit Testing,Storyboard,我不知道如何在单元测试中执行segue以便运行prepareforsgue 我尽最大努力用单元测试覆盖所有内容,以下是我正在尝试的: - (void)setUp { [super setUp]; _mainVC = [[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:kMainVC

我不知道如何在单元测试中执行segue以便运行prepareforsgue

我尽最大努力用单元测试覆盖所有内容,以下是我正在尝试的:

- (void)setUp {

    [super setUp];
    _mainVC = [[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]
                      instantiateViewControllerWithIdentifier:kMainVC];
    _detailsVC = [[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]
                      instantiateViewControllerWithIdentifier:kDetailsVC];
}

- (void)test_prepareForSegue_will_set_confNumber_on_DetailsVC {

   UIStoryboardSegue *segue = [UIStoryboardSegue segueWithIdentifier:kDetailsSegueId source:_mainVC destination:_detailsVC performHandler:^{
        // do anything here ???
    }];

    [segue perform];
    expect(_detailsVC.textFieldStr).to.equal(@"123456abc");
}
我注意到,当我在主viewcontroller中放置断点时,从未命中prepareForSegue。

DUH

只需在测试的ViewController上调用PrepareForsgue:)

只需在测试的ViewController上调用PrepareForsgue:)

UIStoryboardSegue *segue = [UIStoryboardSegue segueWithIdentifier:kDetailsSegueId source:_mainVC destination:_detailsVC performHandler:^{
        // do nothing here
    }];

[_mainVC prepareForSegue:segue sender:self];
expect(_detailsVC.confNumber).to.equal(@"123456abc");