I want to test a ViewController hierarchy without using XCUITests, because they take a huge ton longer than plain old XCTests.
I've had some success but I can't seem to create a ViewController hierarchy more than one level deep.
Here's a test case demonstrating the issue:
class VCHierarchyTests: XCTestCase {
func test_CanMakeViewControllerHierarchy() {
let baseVC = UIViewController()
let vcToPresent = UIViewController()
let vcOnTopOfThat = UIViewController()
let vcOnTopOfThatOnTopOfThat = UIViewController()
newKeyWindowWith(root: baseVC)
baseVC.present(vcToPresent, animated: false)
vcToPresent.present(vcOnTopOfThat, animated: false)
vcOnTopOfThat.present(vcOnTopOfThatOnTopOfThat, animated: false)
//this passes:
XCTAssertNotNil(baseVC.presentedViewController)
//this fails:
XCTAssertNotNil(vcToPresent.presentedViewController)
//this fails:
XCTAssertNotNil(vcOnTopOfThat.presentedViewController)
}
private func newKeyWindowWith(root viewController: UIViewController){
let window = UIWindow(frame: UIScreen.main.bounds)
window.makeKeyAndVisible()
window.rootViewController = viewController
}
}
Is there a way to construct ViewController hierarchies without XCUITest?