samedi 26 mars 2016

ViewController Unit tests fails when trying to cast same types [duplicate]

I am trying to write unit tests to test the methods within my view controllers. Here is one example:

import XCTest

class MyJobsScreenTests: XCTestCase {

    var myJobsViewController: MyJobsController!

    override func setUp() {
        super.setUp()

        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        myJobsViewController = storyboard.instantiateViewControllerWithIdentifier("MyJobsViewController") as! MyJobsController // THIS LINE CRASHES
        myJobsViewController.loadView()
    }

    override func tearDown() {
        // Put teardown code here. This method is called after the invocation of each test method in the class.
        super.tearDown()
    }

    func testTableRefresh() {
        let refreshControl = UIRefreshControl()
        myJobsViewController.refreshTable(refreshControl)
    }
}

However, while running the tests, the setup crashes (see comment on line above) with the following error:

Could not cast value of type 'Gourier.MyJobsController' (0x10ea17210) to 'Gourier.MyJobsController' (0x1266aeb70).

I'm confused about why Xcode would fail to do this cast when the types are exactly the same? Or, in general, is there a better way to setup view controllers in order to unit test their methods?

Aucun commentaire:

Enregistrer un commentaire