How to Use go test -coverprofile and go tool cover

Generate a Go test coverage profile with go test -coverprofile and visualize it using go tool cover -html or -func.

Run go test -coverprofile=c.out to generate a coverage profile, then use go tool cover to visualize it.

go test -coverprofile=c.out ./...
go tool cover -html=c.out
go tool cover -func=c.out

The -html flag opens a browser with annotated source code, while -func lists coverage percentages for each function in the terminal.