How to import my App module into MyAppUITests file?
This is a response from Apple:
UI tests execute differently from Unit tests - Unit tests run inside your application process so they can access your application code. UI tests execute in a separate process, outside your application, so they can simulate how the user interacts with the application. It’s not expected that you will be able to access your app class from a UI test.
Every object you need access to in UI Tests must be part of the UI Test target. This includes object dependencies. It's a slippery slope, and rather a mess.
Rather than having your tests know about your app, try turning it around and have your app know that it's being tested. One way is to use the launchArguments
property:
app = XCUIApplication() app.launchArguments.append("TestMode") app.launch()
Then in your app:
if NSProcessInfo.processInfo().arguments.contains("TestMode") { // I am running in test mode }
In your case the app could then set the NSUserDefaults accordingly.