Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import my App 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?
    }
}

Once I tap UITabBarItem I change the value of DBAppSettings.mode, so here I would like to have an access to my DBAppSettings.mode property to check if it is really changed.

I noticed that there is one weird thing, when I build my app, and check what was built, there is no build for my UITest target. Is it important?

enter image description here

like image 994
Bartłomiej Semańczyk Avatar asked Aug 02 '15 06:08

Bartłomiej Semańczyk


2 Answers

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.

like image 104
Bartłomiej Semańczyk Avatar answered Oct 06 '22 00:10

Bartłomiej Semańczyk


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.

like image 24
Jereme Avatar answered Oct 06 '22 00:10

Jereme