尝试在iOS中对segue进行单元测试,测试总是失败

时间:2018-03-01 11:17:24

标签: ios swift xcode unit-testing xctest

我正在尝试为segue编写单元测试。我的代码看起来像

private var sut: PresentViewController!
    // sut is System Under Test
    override func setUp() {
        super.setUp()
        let storyboard = UIStoryboard(name: "Research", bundle: Bundle.main)
        let rootVC = storyboard.instantiateInitialViewController() as? UINavigationController
        self.sut = rootVC?.viewControllers.first as? PresentViewController
        let window = UIWindow(frame: UIScreen.main.bounds)
        window.rootViewController = self.sut
        window.makeKeyAndVisible()
        sut.loadViewIfNeeded()
    }

func testHelpButtonPresentViewController() {
        XCTAssertNil(sut.presentedViewController)
        UIApplication.shared.keyWindow?.rootViewController = self.sut
        self.sut.performSegue(withIdentifier: "showInfoViewController", sender: nil)
        XCTAssertNotNil(sut.navigationController)
        XCTAssertTrue(sut.navigationController?.presentedViewController is DestinationViewController)
    }

获得以下错误 警告:尝试出席< UINavigationController:0x7f845f84c000> on< myScheme.CurrentViewController:0x7f845e7108f0>其视图不在窗口层次结构中!

segue由按钮操作

触发

种类:以模态呈现

演示文稿:来自表格

我的故事板如下:

enter image description here

0 个答案:

没有答案