Code coverage with cocoapods library - iOS Unit Te

2019-02-18 16:25发布

问题:

In Xcode 7, the library for cocoapods library with exclude for the code coverage.

But In Xcode 8, the library will include for code coverage.

Can I had anyway to exclude the library in the code coverage?

Example: Install pod 'TPKeyboardAvoiding' TPKeyboardAvoidingScrollView.m is include in the code coverage.

回答1:

You should disable the Code Coverage for the Targets that you don't want to be covered. If you want all of your pods to not be included in the code coverage you can add on your podfile

#   Disable Code Coverage for Pods projects
post_install do |installer_representation|
   installer_representation.pods_project.targets.each do |target|
       target.build_configurations.each do |config|
            config.build_settings['CLANG_ENABLE_CODE_COVERAGE'] = 'NO'
       end
   end
end

This will disable the Code Coverage for the target of your Pods like in this image

If you now run the test with command + U

I tried with this pod in one of my project and it worked for me. I'm using Xcode Version 8.1 (8B62)

Anyway, I'm still struggling with the same issue for other pods like Cartography. There's a particular setting (which I didn't discover yet) that it seems to override the CLANG_ENABLE_CODE_COVERAGE and the tests still produces the Code Coverage for that.

Let me know if this solve your issue.