基于此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,这是最后一个文件测试包,而不是全部显示。