在XCode 7.1的UItesting中访问应用程序模块时链接器错误
我正在尝试在我的项目中执行一些uitesting。 一切都很顺利,只要我保持简单:loggingtesting用例,添加一些断言,然后运行testing。 这工作正常,但是当我尝试从我的testing中访问应用程序模块时,链接器会引发错误(请参见下文):
在应用程序源文件中:
func foo() { assert(true) }
在UItesting中:
import XCTest @testable import MyApp func testExample() { foo() }
错误:
未定义的符号架构i386:“MyApp.foo() – >()”,引用自:MyAppUITests.MyAppUITests.testExample(MyAppUITests.MyAppUITests)() – >()in MyAppUITests.o ld:symbol(s)not found for架构i386铛:错误:链接器命令失败,退出代码1(使用-v来查看调用)
架构x86_64的未定义符号:MyAppUITests.MyAppUITests(MyAppUITests.MyAppUITests)() – >()in MyAppUITests.o中引用的“MyApp.foo() – >()”,ld:symbol(s)not found for架构x86_64
我有类似的问题报告在这里: https : //forums.developer.apple.com/thread/20609但没有解决scheme。 对我来说就像@testable
根本无法正常工作。 在developer.apple.com上的人尝试通过在设置中添加testing主机和Bundle Loader来解决这个问题,但是我不认为这是正确的方法。 我认为@可@testable
应该使所有的工作,现在看起来不像。 任何帮助感激!
@testable import MainModule
不能用于UItesting,尽pipe它会启用代码完成(可能会让你觉得它有效)。 它目前仅用于unit testing。 这将导致build设失败,如下所示:
ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
解决方法是将源代码文件添加到UItesting目标,然后它将开箱即用(即使没有@testable import
)。
文件检查器 – > 目标成员 – >检查UItesting目标 (除了主目标)
希望苹果将尽快修复,以便我们可以有一个更清洁的方式来使用它。
UItesting是与应用程序分开的一个模块,因此不能像逻辑testing那样在应用程序中运行。 他们共享代码的唯一方法是编译所有需要在这两个模块之间共享的应用程序文件。 检查这个博客,你可以如何实现, https://www.bignerdranch.com/blog/ui-testing-in-xcode-7-part-1-ui-testing-gotchas/
还发现这里提供了一个雷达, https://openradar.appspot.com/23116258
可testing的导入实际上可能导致这个错误。 只要拿出线。 这是UITests不需要的。
在6分钟的通知中,@testable不被Apple开发者使用。 https://www.youtube.com/watch?v=7zMGf-0OnoU&t=1316s