gitlab 单元测试覆盖率之2

GO项目跑整个项目的覆盖率

gitlab-ci.sh 内容如下

set -e echo “mode: atomic” > coverage.txt

for d in $(go list ./… | grep -v vendor | grep -v doc); do
go test -race -coverprofile=profile.out $d
if [ -f profile.out ]; then
cat profile.out | grep -v statements | grep -v atomic >> coverage.txt
rm profile.out
fi done

go tool cover -func=coverage.txt

go 1.10 之后建议使用如下代码

set -e
go test -race -coverprofile=coverage.txt $(go list ./… | grep -v “vendor” | grep -v “doc”)
go tool cover -func=coverage.txt

gitlab页面设置

导航到页面settings/ci_cd 展开节点:General pipelines settings–>Test coverage parsing

输入 total:\s+\(statements\)\s+(\d+.\d+)%

发表评论

电子邮件地址不会被公开。 必填项已用*标注