簡體   English   中英

單元測試:ViewController沒有標識為“ segue id”的segue

[英]Unit testing : ViewController has no segue with identifier : “segue id”

我想測試以下方法:

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

為什么會出現此錯誤,如何解決?

我必須在測試中從情節提要中加載視圖控制器,然后它才能工作。 我能夠在測試中調用viewDidLoad並繼續。

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

我還必須進入情節提要,為此視圖控制器添加一個情節提要ID(MyViewControllerId)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM