Test coverage in Go
Test coverage refers to the portion of ‘system’ code which should be executed - covered - by some test.
Go toolchain provides a command to check this:
1go test -cover
If we want to see what statements are uncovered:
1go test -coverprofile=coverage.out
2go tool cover -html=coverage.out
This will generate an HTML output that will open the browser automatically. The covered code is highlighted in green, uncovered in red, and ignored in grey.
Definitions, constants and so on are just instructions to the compiler, and don’t result in any generated object code in your program binary, so the coverage tool ignores them.
References
- John Arundel, For the Love of Go
#programming #golang #for_the_love_of_go #testing #command #coverage