Gocoverage - Simplifying Go Code Coverage

by Dr. Phil Winder , CEO

Go introduced vendoring into version 1.5 of the language. The vendor folder is used as a dependency cache for a project. Because of the unique way Go handles dependencies, the cache is full code from an entire repository; worts and all. Go will search the vendor folder for its dependencies before it searches the global GOPATH.

Tools have emerged to corral the vendor folder and one of my favourites is glide. However, one thing that hasn’t happened yet is improvements to Go’s code coverage tool. As of 1.7 any attempt to generate a single coverage report for the entire project, excluding the vendor folder, is not possible. Single reports are important for code coverage services such as Coveralls.

So I developed Gocoverage, which is a very simple tool to recurse over all directories in the project (with an optional filter), generate coverage reports with the standard Go coverage tool and collate all reports for upload to services like coveralls. This idea was strongly influenced by gover, which didn’t have the filtering capabilities. But kudos to that.

For example, generating a coverage report and uploading to coveralls is extremely simple:

go get github.com/philwinder/gocoverage
go get github.com/mattn/goveralls
gocoverage
goveralls -coverprofile=profile.cov -repotoken=${COVERALLS_TOKEN}

And that’s it. The command defaults to filtering out hidden directories and the vendor folder. But you are free to change that via the cli parameters.

Check it out. If you need any help with your Go projects, please, get in touch.

More articles

Build a Voice-Based Chatbot with OpenAI, Vocode, and ElevenLabs

Learn to create a chatbot using OpenAI, Vocode, and ElevenLabs for natural voice interactions. An example speech-to-text and text-to-speech system.

Read more

Revolutionizing IVR Systems: Attaching Voice Models to LLMs

Discover how attaching voice models to large language models (LLMs) revolutionizes IVR systems for superior customer interactions.

Read more
}