Checking test coverage
A test coverage report shows which lines of source code were covered by tests.
How to do it...
- To get a quick coverage result, run tests with the
cover
flag:$ go test -cover PASS coverage: 76.2% of statements
- To write a test coverage profile to a separate file so you can get detailed reports on it, give the test run a cover profile file name:
$ go test -coverprofile=cover.out PASS coverage: 76.2% of statements
Then, you can see the coverage report in your browser using:
$ go tool cover -html=cover.out
This command opens the browser and allows you to see which lines were covered by tests.