Xcode 7 - Code coverage data generation failed

前端 未结 19 2649
無奈伤痛
無奈伤痛 2020-12-25 09:32

When I run my tests I get an error:

Code coverage data generation failed.
Unable to retrieve the profile data files from \'UIDevice\'.

相关标签:
19条回答
  • 2020-12-25 10:32

    Cocoapods link_with method can cause this issue!

    I was getting the exact same error on xcode 7.2 - no number of simulator or device resets seemed to clear it up. After completely rebuilding my UITest targets though things worked fine. After spending a lot of time in a massive git diff of the .pbxproj file I found a solution for my project. Im not sure if it addresses the root cause for everyone who is seeing this error but it definitely clears things up for me.

    From the project info below "deployment target", "Configurations" will list all the possible configurations for your application. Expand the configuration you are trying to run and you should see a list of all your targets. In my case cocoapods had automatically added a base configuration for the UITest target:

    Set this to none in the dropdown.
    Next in the menu to the left select your UITest target then build phases You will need to remove check pods manifest.lock link binary with libraries emebd pods frameworks and copy pods resources.

    Finally go to your pod file and check for any mentions of your UITest target or targets. In my case I had been specifying at the top of my podfile:

    platform :ios, '8.4'
    use_frameworks!
    
    link_with 'My App', 'My UITesting Target' 
    
    pod 'A Pod', '~> 1.0'
    

    Instead the podfile should list specific dependencies for each target:

    platform :ios, '8.4'
    use_frameworks!
    
    target 'My App', :exclusive => true do
        pod 'A Pod I want to use in my app', '~> 1.0'
    end
    

    Assuming you weren't using any pods in your UITests the target should build again without errors and tests will run!

    My understanding of root of this problem is that each UITest target builds two separate bundles, one for the app and one for the UITest controller. Unfortunately cocoapods link_with logic modifies all the specified targets to expect the pods.framework in their bundle. The build phase scripts add the framework to the app bundle but not the UITest controller bundle, so then when you launch your tests that UITest controller bundle appears to be missing frameworks and xcode aborts the installation.

    If you were using pods in your UITests you should be able to specify these in the same way:

    target 'My UITesting Target', :exclusive => true do
        pod 'Another Pod I want only for UITesting', '~> 1.0'
    end
    

    And when you run pod install everything should link up correctly.

    0 讨论(0)
提交回复
热议问题