ios - 使用 Cocoapods 的 Xcode 7 UI 测试在设备上失败

标签 ios xcode xctest xcode-ui-testing

尝试在我的设备上运行 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/

相关文章:

swift - 尝试在私有(private) Pod 上运行测试时出错

swift - 如何在没有 View Controller 作为所有者的情况下将 Nib 实例化为 View ?

xcode - 如何在 Xcode Story Board 中添加关于多设备的动态字体大小

ios - 使用 Xcode 7.3/8 在 iOS 上进行 GTest

ios - 创建约束以在以编程方式调整大小的 View 上重新定位按钮

ios - UITextField 上的 Swift 扩展不会在 swift 1.2 和 xcode6.3 上编译

objective-c - 如何从 iOS 应用程序发布到 Facebook 和 Twitter 墙

ios - 如何在运行时为 iOS 禁用 Crashlytics?

ios - 如何使表格 View 单元格中的间距均匀?

ios - Firebase 通知