ios 如何在Xcode中从代码覆盖率中排除Pod

4jb9z9bj  于 2023-11-19  发布在  iOS
关注(0)|答案(7)|浏览(139)

有没有办法将Pod从Code Coverage中排除
我希望只看到我写的代码的代码覆盖率。
虽然这不重要,但我使用的是Xcode 8。

l2osamch

l2osamch1#

这些步骤将有助于:

**1.**将这些行添加到Podfile中

  1. # Disable Code Coverage for Pods projects
  2. post_install do |installer_representation|
  3. installer_representation.pods_project.targets.each do |target|
  4. target.build_configurations.each do |config|
  5. config.build_settings['CLANG_ENABLE_CODE_COVERAGE'] = 'NO'
  6. end
  7. end
  8. end

字符串

**2.**运行pod install

现在您将不会在测试覆盖范围中看到pod。

**注意:**只排除了pod,Swift不排除

展开查看全部
nom7f22z

nom7f22z2#

XCode 10更新

在Xcode 10中,你可以设置你想要为哪些目标启用代码覆盖率。
编辑方案>测试>选项
只需选择“Gather coverage for some targets”并添加您的主项目。


的数据

vmdwslir

vmdwslir3#

要禁用Swift代码的覆盖,您可以使用SWIFT_EXEC的 Package 器(到目前为止,我已经用Xcode 9.3验证了这一点)。因此,完整的解决方案(包括Swift)如下所示:
添加到你的Podfile(然后调用pod install):

  1. post_install do |installer|
  2. installer.pods_project.targets.each do |target|
  3. target.build_configurations.each do |configuration|
  4. configuration.build_settings['CLANG_ENABLE_CODE_COVERAGE'] = 'NO'
  5. configuration.build_settings['SWIFT_EXEC'] = '$(SRCROOT)/SWIFT_EXEC-no-coverage'
  6. end
  7. end
  8. end

字符串
将以下脚本(将其命名为SWIFT_EXEC-no-coverage)放在源目录树的根目录下(根据需要使用chmod +x):

  1. #! /usr/bin/perl -w
  2. use strict;
  3. use Getopt::Long qw(:config pass_through);
  4. my $profile_coverage_mapping;
  5. GetOptions("profile-coverage-mapping" => \$profile_coverage_mapping);
  6. exec(
  7. "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc",
  8. @ARGV);


这里有一个链接到相应的要点:https://gist.github.com/grigorye/f6dfaa9f7bd9dbb192fe25a6cdb419d4

展开查看全部
cgyqldqp

cgyqldqp4#

1.在左侧的项目导航器中单击您的Pods项目
1.在右侧,打开项目和目标列表(如果尚未打开);然后单击Pods项目名称(而不是目标)。
1.单击“生成设置”。
1.在搜索栏中,搜索“CLANG_ENABLE_CODE_COVERAGE”。
1.将“启用代码覆盖率支持”更改为“否”。
1.重新运行测试。

fbcarpbf

fbcarpbf5#

如果你正在开发一个pod,并希望只为你的代码覆盖率:

  1. # Disable Code Coverage for Pods projects except MyPod
  2. post_install do |installer_representation|
  3. installer_representation.pods_project.targets.each do |target|
  4. if target.name == 'MyPod'
  5. target.build_configurations.each do |config|
  6. config.build_settings['CLANG_ENABLE_CODE_COVERAGE'] = 'YES'
  7. end
  8. else
  9. target.build_configurations.each do |config|
  10. config.build_settings['CLANG_ENABLE_CODE_COVERAGE'] = 'NO'
  11. end
  12. end
  13. end
  14. end

字符串

展开查看全部
bbuxkriu

bbuxkriu6#

根据@Tung Fam的回答,为某些Pod添加排除列表

  1. # Disable Code Coverage for projects listed in excluded_pods
  2. excluded_pods = ['Pod1', 'Pod2', 'Pod3']
  3. post_install do |installer_representation|
  4. installer_representation.pods_project.targets.each do |target|
  5. next if !excluded_pods.include?(target.name)
  6. target.build_configurations.each do |config|
  7. config.build_settings['CLANG_ENABLE_CODE_COVERAGE'] = 'NO'
  8. end
  9. end
  10. end

字符串

a6b3iqyw

a6b3iqyw7#

使用此代码删除它适用于Swift和objc Pod

  1. post_install do |installer|
  2. installer.pods_project.targets.each do |target|
  3. target.build_configurations.each do |config|
  4. # remove code coverage
  5. config.build_settings['CLANG_ENABLE_CODE_COVERAGE'] = 'NO'
  6. config.build_settings['ENABLE_CODE_COVERAGE'] = 'NO'
  7. end
  8. end
  9. end
  10. end

字符串

相关问题