A test suite for any package is explicitly testing different code paths and identifies how your code works using different inputs. But does it actually manage to cover all the code branches that exist in your code? How about all the different functions?
One way to answer these questions is to thoroughly look at all the tests written (by you and your colleagues) and understand if there are any gaps. The easiest way to do that though is to use a tool, and in the case of Go this tool is called cover
.
There is an excellent blog post on the Go Blog, called “The cover story” that describes how Go uses the cover
tool to generate reports that I definitely recommend reading. In this post we are going to analyze a few parts of how the cover
tool works and also provide a way to use it for packages which include sub-packages.
Continue reading “Test coverage in Go, working with packages and sub-packages” →