我正在为具有在情节提要中创建的元素(如按钮)的控制器编写单元测试。我正在尝试在单元测试中实例化视图控制器,以便可以访问这些元素而不会导致应用程序崩溃。但是,我试图实例化情节提要的方式导致Xcode在我调用instantiateViewController
命令的行上引发SIGABRT错误。
这是我用来尝试在单元测试文件中实例化情节提要的代码:
func testAreaActionsViewController() {
let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: self.classForCoder))
let viewController = storyboard.instantiateViewController(withIdentifier: "AreaActionsViewController") as! AreaActionsViewController
// view.loadView()
//
// view.viewDidLoad()
}
有人知道为什么它会抛出SIGABRT吗?我在情节提要中验证了标识符为AreaActionsViewController,并在Main.storyboard中将目标设置为包括测试目标。
答案 0 :(得分:0)
很抱歉,但是我遇到了同样的问题,我解决了删除此问题的问题:
@testable import ProjectName