Linker error in UI Test Target

I am using XCode 7.1 Beta to develop an app in Swift 2.0. I am trying to access a few classes in the app (e.g. AppDelegate) from the UI Test class. I have enabled testability in the build settings for the app and added this line in the test class:

@testable import MyApp


I am accessing the AppDelegate like this:

override func tearDown() {
        super.tearDown()
        let delegate : AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
        delegate.myFunc()
}


However, I am running into a linker error:


Undefined symbols for architecture x86_64:
  "type metadata accessor for MyApp.AppDelegate", referenced from:
      MyAppUITests.MyAppUITest.tearDown (MyAppUITests.MyAppBasicUITest)() -> () in MyAppBasicUITest.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)


Same error when I access any other class in the app. Any idea how to access classes in the app from the test app ? Is it supported ?

Replies

I have the same issue and I can't find a solution. Have you figured out a way on solving it?

I got around this by copying build settings for "Linking->Bundle Loader" and "Testing->Test Host" from what I had in my Unit Test target


That being said, I now get a SIGKILL at [[[XCUIApplication alloc] init] launch];

Running into the same problem. Any ideas that doesn't lead to a SIGKILL 😝 ?

I've got the same problem too…

Same problem here...

I found solution. Somehow my host aplication falled off: http://prntscr.com/af81si

After i returned it back and checked "Allow testing Host Application APIs" everything started to work again: http://prntscr.com/af82d5

I think this one is answered here.

https://stackoverflow.com/questions/33755019/linker-error-when-accessing-application-module-in-ui-tests-in-xcode-7-1


It seems @testable import is only intended for UITests. I still encounter this problem with XCode9 and the only solution seems to be to add the classes that you need to the UITesting target.