Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access the App Delegate from a UI Test?

I want to access a particular property router from the App Delegate of the launched app during a UI Test, but I can't figure out if this is possible or not. I have tried:

let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
let router = appDelegate.router

but this gives a failure and won't even build. I am using @testable on my project module. Any ideas?

like image 795
Tometoyou Avatar asked Jun 28 '16 19:06

Tometoyou


1 Answers

Xcode UI testing is designed such that the test code can only see what a user can see, so no objects from the application under test can be used or inspected in the test code. This is also why the views on the screen are represented as XCUIElement objects instead of UIView descendants.

The UI tests run in a separate executable from the application under test. The only way to communicate additional information from the app to a UI test is by constructing a string containing the information and using it as the accessibility identifier for an element.

If you want to test something that requires access to an object from the application code, it is most likely that you need to write a unit test instead of a UI test.

like image 114
Oletha Avatar answered Oct 31 '22 15:10

Oletha