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

标签 ios xcode-ui-testing

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

我首先成功配置了单元测试,我尝试对 UI 测试执行相同的操作。添加新的 UI 测试包目标后,这是我的 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()
    }
}

我收到这个错误:

Running tests... The bundle “MyProjectUITests” couldn’t be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle.

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

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

Reason: image not found)

怎么了?感谢您的帮助。

编辑:作为引用,当我从我的 UI 测试目标中删除那个 Toast_swift pod 并让它只在我的应用程序和单元测试目标中时,它工作正常。

最佳答案

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

我仍然有点困惑为什么这会成为一个问题,但是使用此脚本将 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 

关于ios - 无法加载包 “MyProjectUITests”,因为它已损坏或缺少必要的资源。尝试重新安装 bundle ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52666055/

相关文章:

iphone - 限制 UISCrollView 向上滚动

ios - 当 View 出现在屏幕上时,如何让键盘将 View 向上推? Xcode swift

xcode7 - 如何获得XCUIElement的值?

ios - UIPickerView 同一组件具有不同的行高

objective-c - 如何缩放和平滑旋转?

ios - 'NSInvalidArgumentException',原因 : '-[UIPopoverController initWithContentViewController:] called when not running under UIUserInterfaceIdiomPad.'

ios - 在 XCode 中进行 UI 测试期间无法访问自定义 View

ios - 从命令行为 iOS 应用程序运行单独的 XCTest(UI、单元)测试用例

ios - 断言失败 : UI Testing Failure - Failure fetching attributes for element

ios - 无法在旧项目上运行 UI 测试