Test Coverage and testify
go test -cover and the testify assertion library
go test -cover
Add -cover to any go test command to print the coverage percentage for each package.
go test -cover ./...
// ok myapp 68.4% of statementsCoverage profile
Generate a coverage profile file and view it as HTML to see which lines are covered:
go test -coverprofile=c.out ./...
go tool cover -html=c.out -o coverage.htmlAll lessons in this course
- Writing Unit Tests with testing
- Table-Driven Tests
- Test Doubles: Mocks and Stubs
- Test Coverage and testify