Generating code coverage reports
In this section, we will cover how to generate coverage reports with Go. Test coverage describes how much of a package's code is exercised by running the package's tests.
Run the following command to generate a file that holds statistics about how much code is being covered by the tests you've written in the previous section:
GIN_MODE=release go test -v -coverprofile=coverage.out ./...
The command will run the tests and display the percentage of statements covered with those tests. In the following example, we're covering 16.9% of statements:
The generated coverage.out
file contains the number of lines covered by the unit tests. The full code has been cropped for brevity, but you can see an illustration of this here:
mode: set /Users/mlabouardy/github/Building-Distributed-Applications-in-Gin/chapter7/api-without-db/main.go:51.41,53.2 1 1 /Users/mlabouardy/github...