有没有办法从代码覆盖范围中排除Pods? 我想看看Code Coverage仅针对我编写的代码。
不是它应该重要,但我正在使用Xcode 8。
这些步骤将有助于:
1.将这些行添加到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
2.运行pod install
现在你不会在测试覆盖范围内看到pods。
注意:它只排除了Objective-c pod而不是Swift
要禁用swift代码的覆盖,可以使用SWIFT_EXEC的包装器(到目前为止我使用Xcode 9.3验证了这一点)。因此,完整的解决方案(包括Swift)将如下:
附加到您的Podfile(之后调用pod install
):
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
end
end
将以下脚本(将其命名为SWIFT_EXEC-no-coverage)放在源树的根目录(必要时为chmod + x):
#! /usr/bin/perl -w
use 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);
这是相应要点的链接:https://gist.github.com/grigorye/f6dfaa9f7bd9dbb192fe25a6cdb419d4
如果您正在开发一个pod并希望仅为您的代码覆盖:
# Disable Code Coverage for Pods projects except MyPod
post_install do |installer_representation|
installer_representation.pods_project.targets.each do |target|
if target.name == 'MyPod'
target.build_configurations.each do |config|
config.build_settings['CLANG_ENABLE_CODE_COVERAGE'] = 'YES'
end
else
target.build_configurations.each do |config|
config.build_settings['CLANG_ENABLE_CODE_COVERAGE'] = 'NO'
end
end
end
end