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

问题描述 投票:1回答:3

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

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

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_swift pod并且仅在我的应用程序和单元测试目标中使用它时,它工作正常。

ios xcode-ui-testing
3个回答
5
投票

查看cocoapods github问题跟踪器上的this issue

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

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 

0
投票

尝试添加继承! :search_paths

并在post_install中更改ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES

use_frameworks!

def shared_pods
    pod 'SomePod'
end

target 'App_name' do
    shared_pods
end

target 'App_nameTests' do
    inherit! :search_paths
    shared_pods
end

post_install do |installer|
    installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
            config.build_settings['ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES'] = 'YES'
        end
    end
end

0
投票

我也遇到了这个问题,其他建议都没有奏效。

过了一会儿,我发现在代码中的任何地方专门使用print()会以某种方式强制libswiftSwiftOnoneSupport.dylib加载,问题就会消失。

我正在使用Xcode 10.1,Swift 4.2以及给我这个问题的pod是Nimble。

希望这可以帮助!

© www.soinside.com 2019 - 2024. All rights reserved.