我正在尝试运行一个测试用例,验证某个触发器是否导致正确的pushViewController。在执行此代码时,应用程序正在完成所有工作:
let testController =
ContributionsViewController(
nibName: "ContributionsViewController",
bundle: nil)
println("currentTopVC: \(navigationController?.topViewController)")
navigationController?.pushViewController(testController, animated: true)
println("VC after Pushing: \(navigationController?.topViewController)")
println("No of VC: \(navigationController?.viewControllers.count)")
我可以通过查看输出来证明:
currentTopVC: Optional(<AppMenu.MenuViewController: 0x7fdabae62860>)
VC after Pushing: Optional(<AppMenu.ContributionsViewController: 0x7fdabada39a0>)
No of VC: Optional(2)
在AppDelegate中设置的原始“MenuViewController”被ContributionViewController取代。
但是,从XCTest执行相同的代码会失败。
简单地忽略了pushViewController!
答案 0 :(得分:1)
我想立即解决问题:
您不能使用animated:true
推送viewcontroller它必须是动画的:false。
let testController =
ContributionsViewController(
nibName: "ContributionsViewController",
bundle: nil)
println("currentTopVC: \(navigationController?.topViewController)")
navigationController?.pushViewController(testController, animated: false)
println("VC after Pushing: \(navigationController?.topViewController)")
println("No of VC: \(navigationController?.viewControllers.count)")