samedi 30 juillet 2016

Unit Testing Custom View Controllers in Swift Xcode 7

In my app project I have added a controller called "CalculatorViewController". I have set the target of "CalculatorViewController" to the project as well as the unit test project so I can access the CalculatorViewController inside the unit test project.

I have the following code in unit test:

class CalculatorViewControllerTests: XCTestCase {

    var viewController :CalculatorViewController!

    override func setUp() {
        super.setUp()

        let storyboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())

        self.viewController = storyboard.instantiateViewControllerWithIdentifier("CalculatorViewController") as! CalculatorViewController

    }

I get the following error:

Test Case '-[CalculatorAppTests.CalculatorViewControllerTests testExample]' started.
Could not cast value of type 'CalculatorApp.CalculatorViewController' (0x103144310) to 'CalculatorAppTests.CalculatorViewController' (0x10ee55b18).

Aucun commentaire:

Enregistrer un commentaire