如何从 Xcode 的代码覆盖率中排除 Pod
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39674057/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to exclude Pods from Code Coverage in Xcode
提问by Fengson
Is there a way to excludePods from Code Coverage?
I would like to see Code Coverage only for the code I've written.
有没有办法从代码覆盖范围中排除Pod?
我只想查看我编写的代码的代码覆盖率。
Not that it should matter, but I'm using Xcode 8.
并不是说它应该重要,但我使用的是 Xcode 8。
回答by Tung Fam
These steps will help:
这些步骤将有助于:
1.add these lines to Podfile
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.run pod install
2.运行pod install
Now you won't see pods in test coverage.
现在您不会在测试覆盖率中看到 pod。
Note:It only excludes Objective-c pods but not Swift
注意:它只排除 Objective-c pods 而不是 Swift
回答by kingInTheNorth
回答by Grigory Entin
To disable coverage for swift code you can use a wrapper for SWIFT_EXEC (I verified this so far with Xcode 9.3). Hence the complete solution (incl. Swift) would be the following:
要禁用 swift 代码的覆盖,您可以使用 SWIFT_EXEC 的包装器(到目前为止我已使用 Xcode 9.3 验证了这一点)。因此,完整的解决方案(包括 Swift)如下:
Append to your Podfile (and invoke pod install
after that):
附加到您的 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
Place the following script (name it SWIFT_EXEC-no-coverage) at the root of your source tree (chmod +x as necessary):
将以下脚本(将其命名为 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);
Here's a link to the corresponding gist: https://gist.github.com/grigorye/f6dfaa9f7bd9dbb192fe25a6cdb419d4
这是相应要点的链接:https: //gist.github.com/grigorye/f6dfaa9f7bd9dbb192fe25a6cdb419d4
回答by SeaJelly
- Click on your Pods project in the Project Navigator on the left
- On the right hand side, open project and target list if it's not already open; then click on the Pods project name (NOT the targets).
- Click Build Settings.
- In the search bar, search for "CLANG_ENABLE_CODE_COVERAGE".
- Change "Enable Code Coverage Support" to NO.
- Re-run test.
- 在左侧的 Project Navigator 中单击您的 Pods 项目
- 在右侧,如果尚未打开,请打开项目和目标列表;然后单击 Pods 项目名称(不是目标)。
- 单击构建设置。
- 在搜索栏中,搜索“CLANG_ENABLE_CODE_COVERAGE”。
- 将“启用代码覆盖支持”更改为否。
- 重新运行测试。
回答by Daniel Suia
If you are developing a pod and want to have code coverage just for yours:
如果您正在开发一个 pod 并希望为您的 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