9

Xcode 7.3

Open Radar: rdar://25456632

In my app I have a string enum which I use to define some accessibility identifiers. For example

enum AccessibilityIds:String {
    case ButtonFoo
}

I've built some UI tests where I want to search for controls. So I do something like this:

XCUIApplication().buttons[AccessibilityIds.ButtonFoo.rawValue]

XCode thinks this is fine and does not indicate any errors on the line. However when I compile the UI tests I get this compiler error:

Undefined symbols for architecture x86_64:
"myApp.AccessibilityIds.rawValue.getter : Swift.String", referenced from:
  (extension in myAppUITests):__ObjC.XCTestCase.fooButton (myApp.AccessibilityIds) -> Swift.Bool in TestCaseExtensions.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Cross referencing the UI test target with the unit test target (Which compiles fine and uses the enum), I found that the UI tests did not have the Test Host set. Setting it meant that the UI test code would now compile, however the test itself then failed with a SIGKILL and the error:

testFooButton() encountered an error (Lost connection to test manager service. If you believe this error represents a bug, ...

So it appears that I cannot access enum rawValues in UI test code. Has anyone else come across this and managed to figure it out?

Moin Shirazi
  • 4,372
  • 2
  • 26
  • 38
drekka
  • 20,957
  • 14
  • 79
  • 135
  • Could this be an import issue - needing to add all files to test target? – sschale Mar 31 '16 at 02:49
  • I don't believe so. I import `@testable import myApp`. I've also accessed this enum successfully from the unit tests and since discovered that any property or function defined on the enum is not visible. – drekka Mar 31 '16 at 02:54
  • 1
    There is a known crashing bug involving one-case enums, which is what you've got. Try giving your enum another case (even if you never use it for anything) just to see if that happens to fix the problem. – matt Mar 31 '16 at 03:22
  • The problem appears to be related to your build settings. The error is complaining that the code is missing for the Mac OS X (the simulator) architecture. Have you changed any of your build settings? Those particularly related to the CPU architecture or SDK might be suspect. – Scott Thompson Mar 31 '16 at 05:10
  • @matt - Thanks, I added another case, but it didn't work. :-( – drekka Mar 31 '16 at 05:24
  • @ScottThompson - I've reproduced this error in a brand new project which contains nothing except an enum, the default controller and a single UI test. No build settings where hurt during the construction of this project. I've also cross referenced the build settings between the unit tests and the UI tests. The only difference is the setting of the **Test Host**. I've also now located what appears to be the same problem in another SOF posting. Appears this is an issues with UI tests and internal code. – drekka Mar 31 '16 at 05:27
  • 1
    Any progress? It is still happening to me on Xcode 8.2 – Hola Soy Edu Feliz Navidad Apr 03 '17 at 14:28

2 Answers2

1

I'm still seeing this in Xcode 11.2.1

As a workaround I have placed fileprivate copies of the enums in the Tests.swift file. This is working for me without any issues or warnings.

Mozahler
  • 4,958
  • 6
  • 36
  • 56
  • 1
    I'm also still seeing this. Instead of copypasting code, I set the file in which my enum is defined to have target membership not only in my app's target, but also in my UI tests' targets. – armcknight Dec 25 '19 at 18:07
  • 2
    Actually just found this issue that states that @testable imports aren't meant for UI tests and that any shared code should be factored into a framework that may be linked into both the app target and UI test targets... I feel like I'd already done that in the past and forgotten it! https://stackoverflow.com/questions/33755019/linker-error-when-accessing-application-module-in-ui-tests-in-xcode-7-1?rq=1 – armcknight Dec 25 '19 at 18:11
  • I guess I always knew my workaround was a bit too code-smelly.... Thanks for the link! – Mozahler Dec 26 '19 at 16:33
0

Click the source file go the Target Membership of the right panel, then tick the UITests target. Now it should work without any errors.

enter image description here