[英]a way to test if prepareForSegue does what it's supposed to
我不確定如何在單元測試中執行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永遠不會被擊中。
DUH。
只需在正在測試的ViewController上調用prepareForSegue :)
UIStoryboardSegue *segue = [UIStoryboardSegue segueWithIdentifier:kDetailsSegueId source:_mainVC destination:_detailsVC performHandler:^{
// do nothing here
}];
[_mainVC prepareForSegue:segue sender:self];
expect(_detailsVC.confNumber).to.equal(@"123456abc");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.