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.
Using go test -coverprofile and go tool cover measures how much of your code is actually executed during tests. First, you run your tests with a special flag that saves a report file. Then, you use a tool to turn that report into a visual map or a list of numbers showing which parts of your code are tested and which are not.