我正在尝试为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由按钮操作
触发种类:以模态呈现
演示文稿:来自表格
我的故事板如下: