一个使用 xcrun 和 xccov 从 Xcode 覆盖率报告中提取代码覆盖率结果摘要的工具。
Interpret XCode code coverage results.
Usage:
coverage <results-path> [<target>] [--printFiles] [--printTargets] [--threshold=<amount>]
coverage --help
Arguments:
<results-path> Path to the xcode results file.
<target> The target to produce output for. If this is missing, output is produced for all targets.
Options:
--printFiles Print coverage results for each file in the target(s).
--printTargets Print coverage results for the target(s).
--threshold=<amount> Tf coverage is below this threshold, we will return a non-zero error code.
Exit Status:
The coverage command exits with one of the following values:
0 If the arguments were ok and the threshold was met (or not specified).
1 If there was an error parsing the arguments.
2 If the threshold wasn't met.
使用 SPM 构建
swift build
从构建目录运行
.build/debug/coverage --help
只需将 .build/debug/coverage
复制到其他地方即可安装。
您可以在持续集成运行中使用此工具,以检查您的覆盖率是否保持在某个阈值之上。
例如,要测试 coverage 项目本身是否具有超过 80% 的覆盖率,您可以这样做
xcodebuild test -workspace Coverage.xcworkspace -scheme Coverage -enableCodeCoverage YES -resultBundlePath Test.xcresult
coverage Test.xcresult Coverage --threshold=0.8
如果覆盖率低于阈值,coverage
命令将以非零值退出,这将导致 CI 作业失败。