2016-09-24 103 views
12

有没有办法通过排除来自代码覆盖的豆荚?
我想只看到代码覆盖我写的代码。如何从Xcode的代码覆盖范围中排除豆荚

不是它应该的问题,但我使用的Xcode 8

+0

类似的问题:http://stackoverflow.com/questions/40102012/code-coverage-with- cocopods-libary-ios-unit-test –

回答

12

这些步骤将帮助:

将这些行添加到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

现在你不会在测试覆盖中看到豆荚。

注:只排除了Objective-C的豆荚,但在Project Navigator不斯威夫特

+0

Fab解决方案谢谢!如果它们存在于吊舱中,如何排除'C'文件呢? – DrPatience

3
  1. 点击你的荚项目上留下
  2. 在右手边,打开的项目和目标列表如果它尚未打开;然后点击Pods项目名称(不是目标)。
  3. 单击生成设置。
  4. 在搜索栏中搜索“CLANG_ENABLE_CODE_COVERAGE”。
  5. 将“启用代码覆盖支持”更改为否。
  6. 重新运行测试。
+3

您不应该更改Pods项目,因为这些设置在下一个“pod安装/更新”时会丢失。解决方案@ tung-fam是正确的做法。 – Camsoft

1

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

# 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 
这里