Continuous integration and code coverage in Golang


It took me some time to find the right setup and the right tools to achieve something not that complicated: continuous integration and coverage reports for Golang projects hosted on GitHub.

I’m happy to share my configuration with you, hopefully it will save you some time. I’m using Travis CI for the continuous integration platform and Codecov for code coverage reports. Both are free and easy to setup: you can get just log in using your GitHub account, you will be up and running in under 5 minutes.

Here is the Travis file (.travis.yml) I use:

language: go
  - go get
  - go get
  - go get
  # Vet examines Go source code and reports suspicious construct
  - go vet
  # Run the unit tests suite
  - go test -v ./...
  # Collect coverage reports
  - go list -f '{{if len .TestGoFiles}}"go test -coverprofile={{.Dir}}/.coverprofile {{.ImportPath}}"{{end}}' ./... | xargs -i sh -c {}
  # Merge coverage reports
  - gover . coverprofile.txt
  # Send coverage reports to Codecov
  - bash < (curl -s -f coverprofile.txt

Replace with your GitHub URL and you're good to go! You will be protected against yourself or contributors for your package. Unit tests will not break and coverage will not decrease. Or at least you will know when it happens!

Bonus: fancy badges

I like to put at the beginning of every README file a few information:

  • The status of the latest build (green is reassuring)
  • The software license, so that people immediately know if it's okay to use it for their project
  • A link to the GoDoc website, for documentation
  • The percentage of code covered by unit tests

If you want to do the same, here is what you can write at the very top of your file:

# Travis CI for the master branch
[![Travis CI](](
# Note that this is for the MIT license and it expects a file
[![Software License](](
# Link to GoDoc
# Codecov for the master branch
[![Coverage Status](](

One more time, don’t forget to replace vendor/package (even in URLs) with your details and you’re good to go!


Head to AntoineAugusti/colors to see what it looks like.

Happy coding!

Sounds great? Give me a follow on Twitter or learn more about me.