尝试在我的设备上运行 UI 测试时出现错误:
XCTRunner[1476:104021] The bundle “AppUITests” couldn’t be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle. 2015-11-23 20:58:53.903 XCTRunner[1476:104021] (dlopen_preflight(/var/mobile/Containers/Bundle/Application/FAC2EFB2-92C6-4668-96A7-C77CC5C4AE87/AppUITests-Runner.app/PlugIns/AppUITests.xctest/TrueMostUITests): Library not loaded: @rpath/UIColor_Hex_Swift.framework/UIColor_Hex_Swift Referenced from: /var/mobile/Containers/Bundle/Application/FAC2EFB2-92C6-4668-96A7-C77CC5C4AE87/AppUITests-Runner.app/PlugIns/AppUITests.xctest/AppUITests Reason: image not found)
在这种情况下,它是“UIColor_Hex_Swift.framework”,它在我的 podfile 中。但我从 cocoapods 加载哪些框架并不重要。它在每个框架上都会失败。
我尝试过更改 pod 文件、清理、删除派生数据、重新安装 pod 和更改签名。不,我没主意了。
如果我使用模拟器,一切正常。
这是我的 pod 文件:
platform :ios, '9.0'
workspace './AppWorkspace'
use_frameworks!
inhibit_all_warnings!
link_with 'App', 'AppTests', 'AppUITests'
target 'App', :exclusive => false do
pod 'SwiftyJSON', '~> 2.3.0'
pod 'MQTTKit', :git => 'https://github.com/mobile-web-messaging/MQTTKit.git'
pod 'PromiseKit', '~> 3.0.0'
pod 'UIColor_Hex_Swift',:git => 'https://github.com/yeahdongcn/UIColor-Hex-Swift.git', :branch => 'Swift-2.0'
pod 'OHHTTPStubs', '~> 4.3.0'
pod 'Alamofire', '~> 3.1.0'
end
def testing_pods()
# pod 'SwiftyJSON', '~> 2.3.0'
# pod 'MQTTKit', :git => 'https://github.com/mobile-web-messaging/MQTTKit.git'
# pod 'PromiseKit', '~> 3.0.0'
pod 'UIColor_Hex_Swift',:git => 'https://github.com/yeahdongcn/UIColor-Hex-Swift.git', :branch => 'Swift-2.0'
# pod 'OHHTTPStubs', '~> 4.3.0'
# pod 'Alamofire', '~> 3.1.0'
end
target 'AppTests', :exclusive => false do
testing_pods
end
target 'AppUITests', :exclusive => false do
testing_pods
end
最佳答案
在我的例子中,我不得不在我的一个 UI 测试中导入 UIKit 和 CoreData。然后确保执行完全干净的构建 (CMD-Shift-k)。
import XCTest
import UIKit
import CoreData
class MyUITests: XCTestCase {
关于ios - 使用 Cocoapods 的 Xcode 7 UI 测试在设备上失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33879799/