vin*_*thp 11 iphone unit-testing ios swift
我写了下面的测试用例,它在swift 1.1中运行良好.但在1.2中它的突破.
class AboutViewController_Tests: XCTestCase
{
//var storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: NSBundle(forClass: self.dynamicType)) // Used in swift 1.1
var storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle:NSBundle.mainBundle()) // Replaced this in swift 1.2
var aboutViewController:AboutViewController!
override func setUp()
{
super.setUp()
aboutViewController = storyboard.instantiateViewControllerWithIdentifier("AboutViewController") as! AboutViewController
aboutViewController.viewDidLoad()
XCTAssertNotNil(aboutViewController, "About not nil")
}
}
Run Code Online (Sandbox Code Playgroud)
运行单元测试时出错
无法将'testProject.AboutViewController'(0x105b0ad30)类型的值转换为'testProjectTests.AboutViewController'(0x116e51d20).
我已经做了足够的研究来解决这个问题.但无法做到这一点.我希望你们中的一些人遇到这个问题,并能够在这里帮助我.
小智 13
我有同样的问题,解决方案是:
Main和AboutViewController测试目标UIStoryboard(name: "Main", bundle:NSBundle.mainBundle())为
UIStoryboard(name: "Main", bundle: NSBundle(forClass: self.classForCoder))这样,您将加载故事板并从测试目标包中初始化控制器,而不是从主目标包中使用它. 请查看此链接了解详情
小智 13
几分钟前我遇到了同样的问题.这是我如何解决它.
var storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle:NSBundle(forClass: self.dynamicType))
self.vc = storyboard.instantiateViewControllerWithIdentifier("gettingStartedView") as! MainViewController
self.vc.loadView()
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助!
| 归档时间: |
|
| 查看次数: |
2603 次 |
| 最近记录: |