Would you like to measure code coverage on Code Climate in Go?
Viewing Coverage Result
All you need to is adding -coverprofile c.out
option to go test
command.
$ go test ./... -coverprofile c.out
c.out
is a test coverage result file.
Sending Coverage Result
This is a sample to send coverage result on TravisCI.
# Install test-reporter
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
chmod +x ./cc-test-reporter
# before build step
./cc-test-reporter before-build
# RUN TEST HERE
go test ./... -coverprofile c.out
# after build step
./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
Sample Setting for TravisCI
Whole sample for TravisCI:
language: go
before_script:
- 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
script:
- go test ./... -coverprofile c.out
after_script:
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
Reference
- test-reporter/go_examples.md at master · codeclimate/test-reporter
- The cover story - The Go Blog
- Configuring Test Coverage