How to exclude Pods from Code Coverage in Xcode
These steps will help:
1. add these lines to Podfile
# Disable Code Coverage for Pods projectspost_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 endend
2. run pod install
Now you won't see pods in test coverage.
Note: It only excludes Objective-c pods but not Swift
To disable coverage for swift code you can use a wrapper for SWIFT_EXEC (I verified this so far with Xcode 9.3). Hence the complete solution (incl. Swift) would be the following:
Append to your Podfile (and invoke pod install
after that):
post_install do |installer| installer.pods_project.targets.each do |target| target.build_configurations.each do |configuration| configuration.build_settings['CLANG_ENABLE_CODE_COVERAGE'] = 'NO' configuration.build_settings['SWIFT_EXEC'] = '$(SRCROOT)/SWIFT_EXEC-no-coverage' end endend
Place the following script (name it SWIFT_EXEC-no-coverage) at the root of your source tree (chmod +x as necessary):
#! /usr/bin/perl -wuse strict;use Getopt::Long qw(:config pass_through);my $profile_coverage_mapping;GetOptions("profile-coverage-mapping" => \$profile_coverage_mapping);exec( "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc", @ARGV);
Here's a link to the corresponding gist: https://gist.github.com/grigorye/f6dfaa9f7bd9dbb192fe25a6cdb419d4