我愿意为我的应用添加单元和 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/