在 Xcode 7.1 的 UI 测试中访问应用程序模块时出现链接器错误 [英] Linker error when accessing application module in UI tests in Xcode 7.1

查看:18
本文介绍了在 Xcode 7.1 的 UI 测试中访问应用程序模块时出现链接器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的项目中实现一些 UI 测试.只要我保持简单,一切都很好:记录测试用例,添加一些断言,然后运行测试.这工作正常,但是当我尝试从我的测试中访问应用程序模块时,链接器会抛出一个错误(见下文):

I'm trying to implement some UI tests in my project. Everything goes fine as long as I keep it simple: record the test case, add some asserts, then run the test. This works fine, however when I try to access the application module from inside my test, the linker throws an error (See below):

在应用程序源文件中:

func foo() {
   assert(true)
}

在 UI 测试中:

import XCTest
@testable import MyApp

func testExample() {
    foo()
}

错误:

架构 i386 的未定义符号:MyApp.foo () -> ()",参考自:MyAppUITests.MyAppUITests.testExample (MyAppUITests.MyAppUITests)() -> () 在 MyAppUITests.old 中:未找到体系结构 i386 clang 的符号:错误:链接器命令退出代码 1 失败(使用 -v 查看调用)

Undefined symbols for architecture i386: "MyApp.foo () -> ()", referenced from: MyAppUITests.MyAppUITests.testExample (MyAppUITests.MyAppUITests)() -> () in MyAppUITests.o ld: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see invocation)

架构 x86_64 的未定义符号:MyApp.foo () -> ()",参考自:MyAppUITests.MyAppUITests.testExample (MyAppUITests.MyAppUITests)() -> () 在 MyAppUITests.old 中:未找到架构 x86_64 的符号

Undefined symbols for architecture x86_64: "MyApp.foo () -> ()", referenced from: MyAppUITests.MyAppUITests.testExample (MyAppUITests.MyAppUITests)() -> () in MyAppUITests.o ld: symbol(s) not found for architecture x86_64

我在这里发现了类似的问题:https://forums.developer.apple.com/thread/20609但没有解决办法.在我看来, @testable 根本无法正常工作.developer.apple.com 上的人试图通过在设置中添加测试主机和捆绑加载器来解决问题,但我认为这不是正确的方法.我认为 @testable 应该让一切正常工作,目前看起来不像.任何帮助表示赞赏!

I have foud similar issue reported here: https://forums.developer.apple.com/thread/20609 but no solution. Seems to me like the @testable simply doesn't work correctly. The guy on the developer.apple.com tried to workaround by adding the Test Host and Bundle Loader in the settings, but I don't think this is the correct approach. I think the @testable should just make everything work, and it doesn't look like it at the moment. Any help appreciated!

推荐答案

@testable import MainModule 不适用于 UI 测试,但它会启用代码完成(可能会让你觉得它有效).到目前为止,它仅用于单元测试.这会导致构建失败,例如:

@testable import MainModule won't work for UI test, though it would enable code completion (may make you feel it works). It's designed only for unit test so far. And it would lead to build failure, something like:

ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

解决方法是将源代码文件也添加到 UI 测试目标中,然后它会开箱即用(即使没有 @testable import).

The workaround is to add the source code file to UI test target as well, then it will work out of the box (even without @testable import).

File Inspector -> Target Membership -> 检查UI测试目标(除了主要目标)

File Inspector -> Target Membership -> check UI test target (in addition to main target)

希望 Apple 尽快修复它,以便我们能够以更清洁的方式使用它.

Hope Apple will fix it soon so that we can have a cleaner way to use it.

这篇关于在 Xcode 7.1 的 UI 测试中访问应用程序模块时出现链接器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆