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

查看:142
本文介绍了在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.o中:lb:
符号未找到架构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)() - >()in MyAppUITests.o ld:
符号未找到架构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上的那个人试图通过在设置中添加Test Host和Bundle Loader来解决这个问题,但我不认为这是正确的方法。我认为 @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).

文件检查器 - > 目标会员 - >检查 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天全站免登陆