单独测试视图控制器

时间:2018-05-04 09:42:19

标签: ios swift unit-testing testing quick-nimble

我在我的应用程序中使用Quick/Nimble进行测试。这是我第一次做测试。我的应用程序中有三个VC嵌入navigationController,如下所示:

StoryBoard1(NAV -> VC1 -> VC2)->StoryBoard2(VC3).

我想分别测试每个viewController的含义,例如当VC3的测试启动时我不想启动VC1,我需要测试直接进入VC3并测试它,请记住VC3位于单独的storyBoard中,并且它们在第一个storyBoard中共享一个NAV。我试着这样做。

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

        }
    }
}

但它没有推向VC3,并且在推出时它只停留在VC1上。我做错了吗?

0 个答案:

没有答案