23

I got an error:

Undefined symbols for architecture x86_64: "DirectBistro.DBTabBarOrderedIndexesKey.unsafeMutableAddressor : Swift.String", referenced from: DirectBistroUITests.TabBarControllerTests.setUp (DirectBistroUITests.TabBarControllerTests)() -> () in TabBarControllerTests.o ld: symbol(s) not found for architecture x86_64

This is my simple UITest class:

import XCTest
@testable import DirectBistro

class TabBarControllerTests: XCTestCase {

    override func setUp() {
        super.setUp()

        let defaults = NSUserDefaults.standardUserDefaults()
        defaults.setObject([], forKey: DBTabBarOrderedIndexesKey)
        defaults.synchronize()
    }
}

This is how it is defined in DBTabBarController.swift:

let DBTabBarOrderedIndexesKey = "TabBarOrderedIndexesKey"

Info pane:

enter image description here

General pane:

enter image description here

Bartłomiej Semańczyk
  • 59,234
  • 49
  • 233
  • 358

4 Answers4

22

The conslusion is: it is not going to work.

I report it as a bug to Apple, and got a response:

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.

Bartłomiej Semańczyk
  • 59,234
  • 49
  • 233
  • 358
7

It is possible to access application code from your UI tests. Just add the source file to the UI test target:

enter image description here

You can then access that application code from within your UI test code:

enter image description here

But bear in mind that the application code you're accessing thus from your UI Test is code running in your UI Test target (MyAppUITests), it does not correspond to the code running in the actual app target (MyApp). So do not use it to inspect or modify application state.

Eric
  • 16,003
  • 15
  • 87
  • 139
  • I have an SDK that I use in my app using cocoa pods. How would I access the SDK code from the UI Test target? – Shaked Sayag Jul 12 '20 at 19:07
  • 1
    @ShakedSayag In your Podfile, add the SDK's pod to your main target *and* to the UI Test target (under `target 'MyAppUITests'`) as well. – Eric Jul 13 '20 at 20:04
2

I had the same problem when I added my swift package and tried to use a string variable inside it. The fix is just to add the swift package in the frameworks, libraries section in the target General sectionenter image description here

Khaled Annajar
  • 15,542
  • 5
  • 34
  • 45
0

I received similar error while running test case. I identified that there were certain string values being referred in my test case from another file in the main iOS app project. They couldn't be accessed here. I solved it by creating a local constant in my test case method. You may please suggest a better way.

Dhananjay M
  • 1,851
  • 22
  • 18