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

use*_*146 62 ios travis-ci swift uitest

由于以下错误,我无法运行我的测试用例:

  • 无法加载捆绑"UITests",因为它已损坏或缺少必要的资源.尝试重新安装捆绑包.
  • 未加载库:@ rpath/Alamofire.framework/Alamofire.
  • 原因:找不到图像

尝试搜索和解决,因为两天但无法解决这个问题可以有人请帮助.

Rom*_*mov 26

我能够使用Xcode 10.1生成的项目重现此问题.我使用Swift 4.2和CocoaPods作为依赖管理器.我有以下Podfile:

# Uncomment the next line to define a global platform for your project
platform :ios, '10.0'

target 'MyApp' do
  # Comment the next line if you're not using Swift and don't want to use dynamic frameworks
  use_frameworks!

  # Pods for MyApp
  pod 'Alamofire', '4.8.1'

  target 'MyAppTests' do
    inherit! :search_paths
    # Pods for testing
  end

  target 'MyAppUITests' do
    inherit! :search_paths
    # Pods for testing
  end

end
Run Code Online (Sandbox Code Playgroud)

然后我删除了use_frameworks!,看到这个链接了解更多细节:

# Uncomment the next line to define a global platform for your project
platform :ios, '10.0'

target 'MyApp' do

  # Pods for MyApp
  pod 'Alamofire', '4.8.1'    

  target 'MyAppTests' do
    inherit! :search_paths
    # Pods for testing
  end

  target 'MyAppUITests' do
    inherit! :search_paths
    # Pods for testing
  end

end
Run Code Online (Sandbox Code Playgroud)

我也收到了一些这样的警告:

[!] The `MyAppUITests [Debug]` target overrides the `ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES` build setting defined in `Pods/Target Support Files/Pods-MyApp-MyAppUITests/Pods-MyApp-MyAppUITests.debug.xcconfig'. This can lead to problems with the CocoaPods installation
    - Use the `$(inherited)` flag, or
    - Remove the build settings from the target.
Run Code Online (Sandbox Code Playgroud)

这就是我从MyAppUITests构建设置中删除此行的原因:

MyAppUITests构建设置

在那次运行pod deintegrate && pod install之后,问题就消失了.可能对于具有更多依赖项的项目(如此),您需要使用其他解决方案.


Rem*_*m-D 19

在您的测试中,目标更改inherit! :search_pathsinherit! :complete. 请参阅文档了解它的作用。


小智 13

这是因为您的广告连播仅适用于框架目标,而没有适用于测试目标。将测试目标添加到您的Podfile。

范例:

target 'MyFramework' do
  use_frameworks!
  pod 'Alamofire', '~> 4.5'
end

target 'MyFrameworkTests' do
  use_frameworks!
  pod 'Alamofire', '~> 4.5'
end
Run Code Online (Sandbox Code Playgroud)

  • 除了使用该解决方案外,我还发现,测试目标可见的至少一个源文件需要具有“导入<Pod>”(在这种情况下为“导入Alamofire”)才能解决该错误。 (3认同)

Sam*_*uël 12

检查UITest目标“构建设置”中的部署目标是否设置为与您要测试的主机应用程序相同。就我而言,我稍后添加了UITesting目标,并使用默认的部署目标iOS 12创建了该目标。如果您随后尝试在低于12的iOS上运行UITest,则会出现问题中提到的错误。


Mar*_*hea 9

我必须将我的框架的位置添加到目标> mytestTarget> Build Settings> Runpath Search Path下的Runpath搜索路径


Shy*_*mov 9

就我而言,我需要用分隔UI测试目标use_frameworks!

如果您use_frameworks!Podfile顶部的全局某处全局指定,则将UI测试目标从嵌套结构移动到其自身将无济于事

出现错误的Podfile(原始):

platform :ios, '10.0'

inhibit_all_warnings!
use_frameworks!

target 'MyProject' do
  pod 'R.swift', '~> 5.0'
  pod 'Moya/RxSwift', '~> 12.0'
  # and other pods

  target 'MyProjectTests' do
    inherit! :search_paths

    pod 'iOSSnapshotTestCase', '~> 6.0'
  end

  target 'MyProjectUITests' do
    inherit! :search_paths
  end
end
Run Code Online (Sandbox Code Playgroud)

出现错误的Podfile(首先尝试修复):

platform :ios, '10.0'

inhibit_all_warnings!
use_frameworks!

def shared_pods
  pod 'R.swift', '~> 5.0'
end

target 'MyProject' do
  shared_pods

  pod 'Moya/RxSwift', '~> 12.0'
  # and other pods

  target 'MyProjectTests' do
    inherit! :search_paths

    pod 'iOSSnapshotTestCase', '~> 6.0'
  end
end

target 'MyProjectUITests' do
  shared_pods
end
Run Code Online (Sandbox Code Playgroud)

最后的工作Podfile

platform :ios, '10.0'

inhibit_all_warnings!

def shared_pods
  pod 'R.swift', '~> 5.0'
end

target 'MyProject' do
  use_frameworks!

  shared_pods

  pod 'Moya/RxSwift', '~> 12.0'
  # and other pods

  target 'MyProjectTests' do
    inherit! :search_paths

    pod 'iOSSnapshotTestCase', '~> 6.0'
  end
end

target 'MyProjectUITests' do
  shared_pods
end
Run Code Online (Sandbox Code Playgroud)


cat*_*ore 7

当我向项目添加一个框架(这也是一个框架本身)并尝试运行测试时,发生了这个错误。我将其设为可选而不是必需,并且测试成功了。 在此处输入图片说明


use*_*146 1

1

2[![3] 3

  1. 进入构建阶段
  2. 打开 Copy Pods Resources 并复制路径
  3. 粘贴从复制 Pods 资源复制的路径并使用框架更改标签名称资源
  4. 清洁和构建
  5. 运行你的 UITestsFile

  • 问题没有提到他们使用 Cocoapods (2认同)