[Swift UI Testing在访问枚举rawValue时崩溃

问题描述 投票:5回答:1

Xcode 7.3

开放式雷达:rdar:// 25456632

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

enum AccessibilityIds:String {
    case ButtonFoo
}

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

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

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)

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

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

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

ios swift enums ui-testing
1个回答
0
投票

我仍然在Xcode 11.2.1中看到这一点

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

© www.soinside.com 2019 - 2024. All rights reserved.