【问题标题】:Unit testing : ViewController has no segue with identifier : "segue id"单元测试:ViewController 没有带有标识符的 segue:“segue id”
【发布时间】:2013-08-23 07:42:12
【问题描述】:

我想测试以下方法:

- (void)myMethod
{
    self.contact = nil;
    [self performSegueWithIdentifier:@"segue id" sender:self];
}

这是我在测试课上做的:

- (void)testMyMethod
{
    // Call method to test
    [testClass myMethod];

    // Tests
    GHAssertNil(testClass.contact, @"contact should be nil.");
}

运行测试给我错误:

Reason : Receiver (<RS_MainViewController:0x126b6330>) has no segue with identifier 'segue id'

为什么会出现这个错误,解决方法是什么?

【问题讨论】:

  • 您是否在情节提要中为该 segue 指定了 segue id?

标签: ios objective-c unit-testing ios6 gh-unit


【解决方案1】:

我必须在我的测试中从情节提要加载视图控制器,然后它才能工作。我可以在我的测试中调用viewDidLoad 并继续。

UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"MyStoryboard" bundle:nil];
UIViewController* controller = [storyboard instantiateViewControllerWithIdentifier:@"MyViewControllerId"];
AAAMyViewController* viewController = (AAAMyViewController*)controller;

我还必须进入情节提要并为此视图控制器 (MyViewControllerId) 添加情节提要 ID。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-21
    • 1970-01-01
    相关资源
    最近更新 更多