有没有办法将Pod从Code Coverage中排除?我希望只看到我写的代码的代码覆盖率。虽然这不重要,但我使用的是Xcode 8。
l2osamch1#
这些步骤将有助于:
**1.**将这些行添加到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
# 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
字符串
**2.**运行pod install
pod install
现在您将不会在测试覆盖范围中看到pod。
**注意:**只排除了pod,Swift不排除
nom7f22z2#
XCode 10更新
在Xcode 10中,你可以设置你想要为哪些目标启用代码覆盖率。编辑方案>测试>选项只需选择“Gather coverage for some targets”并添加您的主项目。
的数据
vmdwslir3#
要禁用Swift代码的覆盖,您可以使用SWIFT_EXEC的 Package 器(到目前为止,我已经用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 endend
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'
字符串将以下脚本(将其命名为SWIFT_EXEC-no-coverage)放在源目录树的根目录下(根据需要使用chmod +x):
#! /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);
#! /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
cgyqldqp4#
1.在左侧的项目导航器中单击您的Pods项目1.在右侧,打开项目和目标列表(如果尚未打开);然后单击Pods项目名称(而不是目标)。1.单击“生成设置”。1.在搜索栏中,搜索“CLANG_ENABLE_CODE_COVERAGE”。1.将“启用代码覆盖率支持”更改为“否”。1.重新运行测试。
fbcarpbf5#
如果你正在开发一个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
# Disable Code Coverage for Pods projects except MyPod
if target.name == 'MyPod'
config.build_settings['CLANG_ENABLE_CODE_COVERAGE'] = 'YES'
else
bbuxkriu6#
根据@Tung Fam的回答,为某些Pod添加排除列表
# Disable Code Coverage for projects listed in excluded_podsexcluded_pods = ['Pod1', 'Pod2', 'Pod3']post_install do |installer_representation| installer_representation.pods_project.targets.each do |target| next if !excluded_pods.include?(target.name) target.build_configurations.each do |config| config.build_settings['CLANG_ENABLE_CODE_COVERAGE'] = 'NO' end endend
# Disable Code Coverage for projects listed in excluded_pods
excluded_pods = ['Pod1', 'Pod2', 'Pod3']
next if !excluded_pods.include?(target.name)
a6b3iqyw7#
使用此代码删除它适用于Swift和objc Pod
post_install do |installer| installer.pods_project.targets.each do |target| target.build_configurations.each do |config| # remove code coverage config.build_settings['CLANG_ENABLE_CODE_COVERAGE'] = 'NO' config.build_settings['ENABLE_CODE_COVERAGE'] = 'NO' end end endend
# remove code coverage
config.build_settings['ENABLE_CODE_COVERAGE'] = 'NO'
7条答案
按热度按时间l2osamch1#
这些步骤将有助于:
**1.**将这些行添加到Podfile中
字符串
**2.**运行
pod install
现在您将不会在测试覆盖范围中看到pod。
**注意:**只排除了pod,Swift不排除
nom7f22z2#
XCode 10更新
在Xcode 10中,你可以设置你想要为哪些目标启用代码覆盖率。
编辑方案>测试>选项
只需选择“Gather coverage for some targets”并添加您的主项目。
的数据
vmdwslir3#
要禁用Swift代码的覆盖,您可以使用SWIFT_EXEC的 Package 器(到目前为止,我已经用Xcode 9.3验证了这一点)。因此,完整的解决方案(包括Swift)如下所示:
添加到你的Podfile(然后调用
pod install
):字符串
将以下脚本(将其命名为SWIFT_EXEC-no-coverage)放在源目录树的根目录下(根据需要使用chmod +x):
型
这里有一个链接到相应的要点:https://gist.github.com/grigorye/f6dfaa9f7bd9dbb192fe25a6cdb419d4
cgyqldqp4#
1.在左侧的项目导航器中单击您的Pods项目
1.在右侧,打开项目和目标列表(如果尚未打开);然后单击Pods项目名称(而不是目标)。
1.单击“生成设置”。
1.在搜索栏中,搜索“CLANG_ENABLE_CODE_COVERAGE”。
1.将“启用代码覆盖率支持”更改为“否”。
1.重新运行测试。
fbcarpbf5#
如果你正在开发一个pod,并希望只为你的代码覆盖率:
字符串
bbuxkriu6#
根据@Tung Fam的回答,为某些Pod添加排除列表
字符串
a6b3iqyw7#
使用此代码删除它适用于Swift和objc Pod
字符串