2016-09-24 101 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 
這裏