我不确定如何在单元测试中执行 segue,以便 prepareForSegue 运行。
尽我所能用单元测试涵盖所有内容,这就是我正在尝试的:
- (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");
}
我注意到当我放入断点时,主视图控制器中的 prepareForSegue 永远不会被命中。