How to import my application module into MyAppUITests file?

This is my simple test case:

import XCTest @testable import MyApp //it doesn't work 

because of this:

enter image description here

 class TabBarControllerTests: XCTestCase { override func setUp() { super.setUp() let defaults = NSUserDefaults.standardUserDefaults() defaults.setObject([], forKey: DBTabBarOrderedIndexesKey) //key is undefined, because of lack of my app module defaults.synchronize() continueAfterFailure = false XCUIApplication().launch() } func testIsOrderOfTabsSaved() { XCUIApplication().tabBars.buttons["Catering"].tap() //what next? } } 

As soon as I touch UITabBarItem , I change the value of DBAppSettings.mode , so here I would like to access my DBAppSettings.mode property to check if it is really changed.

I noticed that there is one strange thing, when I create my application and check that it was built, there is not built for my target UITest . It is important?

enter image description here

+15
import ios xcode swift xcode-ui-testing
Aug 02 '15 at 6:16
source share
5 answers

This is Apple's answer:

User interface tests run differently than unit tests. Unit tests are performed inside your application process so that they can access your application code. User interface tests are performed in a separate process outside of your application so that they can simulate user interaction with the application. You are not expected to be able to access your application class from a user interface test.

+5
Aug 16 '15 at 20:58
source share

Each object that you need to access in user interface tests must be part of the UI Test target. This includes object dependencies. This is a slippery slope, but rather a mess.

+1
Sep 19 '15 at 4:53 on
source share

Instead of letting your tests know about your application, try turning it on and find out that its application has been verified. One way is to use the launchArguments property:

  app = XCUIApplication() app.launchArguments.append("TestMode") app.launch() 

Then in your application:

  if NSProcessInfo.processInfo().arguments.contains("TestMode") { // I am running in test mode } 

In your case, the application can then set NSUserDefaults accordingly.

+1
Dec 26 '15 at 6:41
source share

Since Apple prevents you from accessing your main application from user interface tests, you might consider reorganizing your application structure to store the relevant data that needs to be checked in a place accessible for user interface tests.

You might consider moving definitions and data from the main application class to a separate class that can be loaded by the test environment.

0
Aug 23 '15 at 12:07 on
source share

I solved the problem with inaccessible characters by pulling some things from my target application into two structures (model and presentation model), which I can then import into my user interface tests.

As for access to the actual memory of the executable file, you cannot, but you can test everything that should appear on the screen somewhere in this mode. I use this statement, for example, check for a table view cell:

 XCTAssertTrue(tables.cells.staticTexts["Cell title I expect to exist"].waitForExistence(timeout: 1)) 

Since you can use access, you can access a pretty decent amount of things this way. I suppose you could add an invisible label with a dump only in the test mode of your application memory.

I also use start arguments to configure my application for user interface tests, as Michael suggested: https://stackoverflow.com/a/412829/

0
Dec 02 '17 at 5:22
source share



All Articles