Xcode 10 UI测试原因:Cocoapods找不到图像

时间:2018-10-05 16:27:54

标签: ios swift xcode cocoapods xcode-ui-testing

我试图在我的应用程序中运行UI测试,但是一旦模拟器启动,我就会得到:

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

2018-10-05 11:04:59.772078-0500 AppUITests-Runner [53273:1645870](dlopen_preflight(/ Users / John / Library / Developer / Xcode / DerivedData / app-ios-client-ewtlrcqcxoeiaudgmthymuhcuxfz / Build / Products /Debug-iphonesimulator/AppUITests-Runner.app/PlugIns/AppUITests.xctest/AppUITests):未加载库:@ rpath / libswiftSwiftOnoneSupport.dylib   引用自:/Users/John/Library/Developer/Xcode/DerivedData/app-ios-client-ewtlrcqcxoeiaudgmthymuhcuxfz/Build/Products/Debug-iphonesimulator/AppUITests-Runner.app/PlugIns/AppUITests.xctest/Frameworks/Alamofire.framework/ Alamofire   原因:找不到图片)

我的UITest是Xcode 10创建的模板,我使用的是Cocoapods 1.5.3和Swift 4.2

我的项目结构:

  • 工作区
    • 自定义框架(此处是Podfile)
    • 应用程序A(我正在运行UITests)
    • 应用B

我的podfile看起来像这样:

platform :ios, '10.0'

inhibit_all_warnings!
use_frameworks!

target 'App Library' do
    use_frameworks!

    pod 'Intercom'
    pod 'Spreedly'
    pod 'Alamofire'
    pod 'IGListKit'
    pod 'CardIO'
    pod 'SwiftKeychainWrapper'
    pod 'OneTimePassword', :git =>   'https://github.com/john/OneTimePassword.git', :branch => 'develop'
    pod 'SnapKit'
    pod 'DateToolsSwift'
    pod 'BetterSegmentedControl'
    pod 'SDWebImage'
    pod 'SwiftLocation'
    pod 'Nuke'
    pod 'Instabug'
    pod 'Mixpanel-swift'


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

    target 'App' do
        project '../App/App'
        inherit! :complete

        use_frameworks!

        pod 'FacebookCore'
        pod 'FacebookLogin'

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

    target 'App Business' do
         project '../App Business/App Business'
         inherit! :complete

         use_frameworks!

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

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

end

# The UI Test target I'm trying to run
target 'AppUITests' do
     inherit! :search_paths
     use_frameworks!
     # Pods for testing
     project '../App/App'
     pod 'Intercom'
     pod 'Spreedly'
     pod 'Alamofire'
     pod 'IGListKit'
     pod 'CardIO'
     pod 'SwiftKeychainWrapper'
     pod 'OneTimePassword', :git => 'https://github.com/john/OneTimePassword.git', :branch => 'develop'
     pod 'SnapKit'
     pod 'DateToolsSwift'
     pod 'BetterSegmentedControl'
     pod 'SDWebImage'
     pod 'SwiftLocation'
     pod 'Nuke'
     pod 'FacebookCore'
     pod 'FacebookLogin'
     pod 'Instabug'
     pod 'Mixpanel-swift'
end

workspace '../app-ios-client'

我尝试使用!inherit:complete!inherit:search_paths将UI测试目标放入目标应用程序中,将其移动到外部,就像上面发布的代码一样。我还清理了构建文件夹,删除了派生数据并重新启动了Xcode,但我仍然遇到这个问题。我也尝试添加import UIKitimport Alamofire,但没有任何效果。在所有可能的修复程序中,我先运行pod deintegrate,然后运行pod install。我认为问题可能与podfile位于我的自定义框架中有关,但老实说我不知道​​。有任何想法吗?谢谢!

3 个答案:

答案 0 :(得分:0)

我通过将podfile中的目标更改为此来解决此问题:

target 'AppUITests' do
    inherit! :search_paths
    use_frameworks!
    # Pods for testing
    project '../App/App'
end

答案 1 :(得分:0)

尝试添加继承! :search_paths

还更改了安装后的 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

答案 2 :(得分:0)

我的修补程序与https://stackoverflow.com/a/54034832/883413类似,除了我不理会post_install部分。

以前,我的podfile结构类似于该问题:

platform :ios, '10.0'

target 'AppName' do
  use_frameworks!

  pod 'PodName'

  target 'AppNameTests' do
    inherit! :search_paths
  end

  target 'AppNameUITests' do
    inherit! :search_paths
  end
end

将其更改为(较新的)结构可以解决此问题:

platform :ios, '10.0'
use_frameworks!

def all_pods
  pod 'PodName'
end

target 'AppName' do
  all_pods
end

target 'AppNameTests' do
  inherit! :search_paths
  all_pods
end

target 'AppNameUITests' do
  inherit! :search_paths
  all_pods
end