I'm trying to perform some really simple feature/functional testing in Swift but I have some doubts that I need to resolve to be able to create useful tests.
I want to verify that a Controller presented by another Controller exists into the Application Navigation Hierarchy (it doesn't matter if the Controller has been presented into a NavigationController, as Modal or whatever).
If I instantiate and show controllers programmatically, directly into the test functions, when I check the On Top controller I always get the Storyboard root controller instead of the controller that I have just instantiated, as if the controllers that I've manually created are never added into the Application Hierarchy.
Here an example of pseudo-code:
func testController(){
// Instantiate a controller
let storyBoard:UIStoryboard = UIStoryboard(name: "Main", bundle: NSBundle(forClass: self.dynamicType))
let controller1 = storyBoard.instantiateViewControllerWithIdentifier("Controller1") as? ControllerOneViewController
controller1.loadView()
// Call a function that instantiates another controller
controller1.pushAnotherController()
// Test that the current shown controller is what we expect...
let rootController = UIApplication.sharedApplication().keyWindow?.rootViewController
XCTAssert(rootController.self == TheExpectedClass, "Controller is not what we expect")
}