首页 > 解决方案 > 无法加载捆绑包“MyProjectUITests”,因为它已损坏或缺少必要的资源。尝试重新安装捆绑包

问题描述

我愿意为我的应用程序添加单元和 UI 测试。

我首先成功地配置了单元测试,我尝试对 UI 测试做同样的事情。这是我的 Podfile,在添加了一个新的 UI 测试包目标之后:

platform :ios, '8.0'
use_frameworks!
inhibit_all_warnings!

def shared_pods
pod 'Bolts'
pod 'Branch'
pod 'FBSDKCoreKit'
pod 'FBSDKLoginKit'
pod 'FBSDKShareKit'
pod 'GoogleAnalytics'
pod 'GooglePlaces'
pod 'Parse'
pod 'Toast-Swift'
end

target 'MyTarget' do
shared_pods
end

target 'MyTargetUITests' do
shared_pods
end

target 'MyTargetUnitTests' do
shared_pods
end

但是,当我尝试运行自动创建的MyProjectUITests测试用例时,它只包含基本设置,甚至没有@testable import MyProject

import XCTest

class MyProjectUITests: XCTestCase {

    override func setUp() {
        continueAfterFailure = false
        XCUIApplication().launch()
    }
}

我收到此错误:

运行测试...无法加载捆绑包“MyProjectUITests”,因为它已损坏或缺少必要的资源。尝试重新安装捆绑包。

(dlopen_preflight(/var/containers/Bundle/Application/5A1FE39F-E675-4A47-9BF4-FBCDB96F5821/MyProjectUITests-Runner.app/PlugIns/MyProjectUITests.xctest/MyProjectUITests):库未加载:@rpath/libswiftSwiftOnoneSupport.dylib

引用自:/private/var/containers/Bundle/Application/5A1FE39F-E675-4A47-9BF4-FBCDB96F5821/MyProjectUITests-Runner.app/PlugIns/MyProjectUITests.xctest/Frameworks/Toast_Swift.framework/Toast_Swift

原因:图片未找到)

怎么了?谢谢你的帮助。

编辑:关于信息,当我从我的 UI 测试目标中删除该Toast_swiftpod 并让它只在我的应用程序和单元测试目标中时,它工作正常。

标签: iosxcode-ui-testing

解决方案


在 cocoapods github 问题跟踪器上查看此问题。

我仍然有点困惑为什么这会成为一个问题,但是设置ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIESYES使用这个脚本为我解决了这个问题。

post_install do |installer|
    installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
            # This works around a unit test issue introduced in Xcode 10.
            # We only apply it to the Debug configuration to avoid bloating the app size
            if config.name == "Debug" && defined?(target.product_type) && target.product_type == "com.apple.product-type.framework"
                config.build_settings['ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES'] = "YES"
            end
        end
    end
end 

推荐阅读