Ios 单元测试Swift-从序列图像板播放视图控制器不工作
我已经编写了下面的测试用例,它在swift 1.1中运行良好。但在1.2中,它被打破了Ios 单元测试Swift-从序列图像板播放视图控制器不工作,ios,iphone,unit-testing,swift,Ios,Iphone,Unit Testing,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 = U
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")
}
}
运行单元测试时出错
无法将“testProject.AboutViewController”(0x105b0ad30)类型的值强制转换为“testProjectTests.AboutViewController”(0x116e51d20)
我已经做了足够的研究来解决这个问题。但是我做不到。我希望你们中的一些人遇到这个问题,并能在这里帮助我。我也遇到过同样的问题,解决方案是:
- 在测试目标中添加情节提要
和Main
AboutViewController
- 将
替换为UIStoryboard(名称:“Main”,bundle:NSBundle.mainBundle())
UIStoryboard(名称:“Main”,bundle:NSBundle(forClass:self.classForCoder))
几分钟前,我遇到了同样的问题。我是这样解决的
这个零钱也帮我解决了
var storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle:NSBundle(forClass: self.dynamicType))
self.vc = storyboard.instantiateViewControllerWithIdentifier("gettingStartedView") as! MainViewController
self.vc.loadView()
class VehicleListControllerSpecs: XCTestCase {
var listController: VehicleListController!
override func setUp() {
super.setUp()
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "VehicleListController") as! VehicleListController
listController = vc
_ = listController.view
// Put setup code here. This method is called before the invocation of each test method in the class.
}
func testListViewHasTableView() {
XCTAssertNotNil(listController.tableView,"view doesnt has tableview")
}
}