gpt4 book ai didi

ios - 单元测试 : ViewController has no segue with identifier : "segue id"

转载 作者:行者123 更新时间:2023-12-01 16:48:04 33 4
gpt4 key购买 nike

我想测试以下方法:

- (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'

为什么我会收到此错误,解决方案是什么?

最佳答案

我必须在测试中从 Storyboard 中加载 View Controller ,然后它才能工作。我可以调用viewDidLoad在我的测试中并继续。

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

我还必须进入 Storyboard 并为此 View Controller (MyViewControllerId) 添加 Storyboard ID。

关于ios - 单元测试 : ViewController has no segue with identifier : "segue id",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18397441/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com