gocov不会将完整的测试覆盖率结果上传到代码环境中

基于此question在StackOverflow上,我将测试覆盖率添加到了Gitlab CI / CD YAML文件中,并且我希望结果可以上传到代码环境中。

- go get github.com/axw/gocov/gocov
- export CC_TEST_REPORTER_ID=My_REPO_ID
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
- chmod +x ./cc-test-reporter
- ./cc-test-reporter before-build
- gocov test -v ./... -coverprofile=out
- ./cc-test-reporter format-coverage --input-type gocov out
- ./cc-test-reporter upload-coverage

该脚本在我所有的程序包中都成功运行了测试,并且CI / CD的输出显示运行了不同程序包中的所有测试,但是将报告上载到codeclimate中仅显示只有一个文件具有test-coverage,这是最后一个文件测试包,而不是全部显示。

gocov不会将完整的测试覆盖率结果上传到代码环境中

iCMS 回答:gocov不会将完整的测试覆盖率结果上传到代码环境中

我在同一个stackoverflow链接中混合了解决方案和另一个答案,最后创建了一个bash文件,并从我的yaml文件中运行它,如下所示,因此报告输出包含所有程序包报告,这是我的脚本:

go get github.com/axw/gocov/gocov
export CC_TEST_REPORTER_ID=My_ID
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
chmod +x ./cc-test-reporter
./cc-test-reporter before-build

for pkg in $(go list ./... | grep -v vendor); do
    go test -coverprofile=$(echo $pkg | tr / -).cover $pkg
done
echo "mode: set" > c.out
grep -h -v "^mode:" ./*.cover >> c.out
rm -f *.cover

./cc-test-reporter after-build
本文链接:https://www.f2er.com/1687425.html

大家都在问