升级到Xcode 5.1后,命令行中的运行单元测试失败

时间:2014-03-11 14:57:15

标签: xcode unit-testing

升级到Xcode 5.1后,从命令行运行的单元测试停止工作。

以下是我运行xcodebuild test -workspace MyApp.xcworkspace -scheme MyApp -sdk iphonesimulator -configuration Debug

时会发生什么
[...]
2014-03-11 15:32:08.392 Test Host[67583:907] Error loading /Users/0xced/Library/Developer/Xcode/DerivedData/MyApp-cdhjwjcbamuhpvfislepygilkusg/Build/Products/Debug-iphonesimulator/MyApp Tests.xctest/MyApp Tests:  dlopen(/Users/0xced/Library/Developer/Xcode/DerivedData/MyApp-cdhjwjcbamuhpvfislepygilkusg/Build/Products/Debug-iphonesimulator/MyApp Tests.xctest/MyApp Tests, 262): Library not loaded: /Developer/Library/Frameworks/XCTest.framework/XCTest
  Referenced from: /Users/0xced/Library/Developer/Xcode/DerivedData/MyApp-cdhjwjcbamuhpvfislepygilkusg/Build/Products/Debug-iphonesimulator/MyApp Tests.xctest/MyApp Tests
  Reason: image not found
IDEBundleInjection.c: Error loading bundle '/Users/0xced/Library/Developer/Xcode/DerivedData/MyApp-cdhjwjcbamuhpvfislepygilkusg/Build/Products/Debug-iphonesimulator/MyApp Tests.xctest'
** TEST SUCCEEDED **

虽然xcodebuild报告 ** TEST SUCCEEDED ** ,但测试显然没有运行。

如何解决此错误?

1 个答案:

答案 0 :(得分:8)

错误表示找不到/Developer/Library/Frameworks/XCTest.framework/XCTest。因此,为了解决这个问题,我使用以下脚本向我的单元测试目标添加了一个运行脚本阶段:

install_name_tool -change "/Developer/Library/Frameworks/XCTest.framework/XCTest" "${SDKROOT}/Developer/Library/Frameworks/XCTest.framework/XCTest" "${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}"

它告诉单元测试包从当前SDK而不是从不存在的/Developer目录加载XCTest框架。

令人惊讶的是,此修复仅在我的计算机上需要,但在我们的CI服务器上不需要。我的机器和CI服务器之间的差异分别包括:

  • 仅限Xcode 5.1的几个Xcode版本(4.6.3 + 5.0.2 + 5.1)
  • 仅限iOS iOS模拟器(6.1 + 7.1)和iOS 7.1模拟器