访问枚举rawValue时,Swift UI测试崩溃

dre*_*kka 5 enums ui-testing ios swift

Xcode 7.3

开放式雷达:rdar:// 25456632

在我的应用程序中,我有一个字符串枚举,用于定义一些可访问性标识符。例如

enum AccessibilityIds:String {
    case ButtonFoo
}
Run Code Online (Sandbox Code Playgroud)

我建立了一些UI测试,我想在其中搜索控件。所以我做这样的事情:

XCUIApplication().buttons[AccessibilityIds.ButtonFoo.rawValue]
Run Code Online (Sandbox Code Playgroud)

XCode认为这很好,并且不指示任何错误。但是,当我编译UI测试时,出现此编译器错误:

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)
Run Code Online (Sandbox Code Playgroud)

将UI测试目标与单元测试目标交叉引用(可以很好地编译并使用枚举),我发现UI测试没有设置测试主机。设置它意味着UI测试代码现在可以编译,但是测试本身随后由于SIGKILL和错误而失败:

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

因此,看来我无法在UI测试代码中访问枚举rawValues。还有其他人遇到这个问题并设法解决吗?

Moz*_*ler 1

我在 Xcode 11.2.1 中仍然看到这个

作为解决方法,我已将枚举的文件私有副本放置在 Tests.swift 文件中。这对我来说很有效,没有任何问题或警告。

  • 实际上只是发现这个问题,指出 @testable 导入不适用于 UI 测试,并且任何共享代码都应该被纳入一个可能链接到应用程序目标和 UI 测试目标的框架中......我觉得我'我过去已经这样做过但忘记了!/sf/ask/2362851361/?rq=1 (2认同)