vendredi 4 mai 2018

Quick/Nimble iOS - Test View Controllers separately

I am using Quick/Nimble for testing in my application. This is the first time I am doing tests. I have three VC in my app embedded in a navigation controller like this : StoryBoard1(NAV -> VC1 -> VC2)->StoryBoard2(VC3). I want to test each view controller separately meaning, when the test for VC3 for example is launched I don't want to launch VC1, I need the test to go directly to VC3 and test it, keep in mind that VC3 is in a separated StoryBoard and they all share one NAV in the first storyboard. I tried doing it like this :

import XCTest
import Quick
import Nimble


@testable import MYApp

class VC3Tests: QuickSpec {

    override func spec() {
        var vc3: VC3!
        var navigationController: UINavigationController!

        beforeEach {

            let storyBoard2 = UIStoryboard(name: "StoryBoard2", bundle: Bundle.main)
            let storyBoard1 = UIStoryboard(name: "StoryBoard1", bundle: Bundle.main)
            navigationController = storyBoard1.instantiateInitialViewController() as! UINavigationController
            vc3 = storyBoard2.instantiateViewController(withIdentifier: NSStringFromClass(VC3.self)) as! VC3
            navigationController.pushViewController(vc3, animated: false)
            expect(navigationController.visibleViewController).toEventually(beAnInstanceOf(VC3.self),timeout: 3,pollInterval: 1)

         _ = navigationController?.view
         _ = vc3.view

        }
    }
}

But it doesn't push to VC3 and when launched it just stays on VC1. Am I doing something wrong?

Aucun commentaire:

Enregistrer un commentaire