简体   繁体   English

测试prepareForSegue是否符合预期的方法

[英]a way to test if prepareForSegue does what it's supposed to

I'm not sure how to perform a segue inside a unit test so that prepareForSegue will run. 我不确定如何在单元测试中执行segue,以便prepareForSegue运行。

Trying my best to cover everything with Unit Tests, here's what I'm trying: 尽我所能用单元测试覆盖所有内容,这就是我正在尝试的内容:

- (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");
}

I notice that prepareForSegue in the main viewcontroller is never hit when I put a breakpoint in. 我注意到,当我放入断点时,主视图控制器中的prepareForSegue永远不会被击中。

DUH. DUH。

just call prepareForSegue on the ViewController under test :) 只需在正在测试的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.

相关问题 这种类型的封闭意味着什么,它如何工作? - What's this type of Closure supposed to mean and how does it work? 发件人在prepareForSegue:sender调用中是什么? - What does sender is in prepareForSegue:sender call? Swift单元测试 - 如何断言CGColor是它应该是什么? - Swift Unit test- How do I assert that a CGColor is what it's supposed to be? 当此API完全符合预期且状态代码为200时,为什么在AFNetworking中将其响应作为“失败”返回? - Why does this API return its response in AFNetworking as a “failure”, when it's exactly what it's supposed to be and the status code is 200? 什么是测试文件存在的快速方法? - What's a quick way to test to see a file exists? 在单元测试中对 UIImage 断言的最佳方法是什么? - What's the best way to assert on a UIImage in a unit test? prepareForSegue 什么时候被调用? - when does prepareForSegue get called? 为什么我的 prepareForSegue 会崩溃 - why does my prepareForSegue Crash 使用prepareForSegue和使用Core Data传递数据之间有什么区别? - What's the difference between passing data using prepareForSegue and using Core Data? iOS:如何在prepareForSegue中设置destinationViewController的图像? - iOS: How to set destinationViewController's image in prepareForSegue?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM