0Pricing
Go Academy · Lesson

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 statements

Coverage 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.html

All lessons in this course

  1. Writing Unit Tests with testing
  2. Table-Driven Tests
  3. Test Doubles: Mocks and Stubs
  4. Test Coverage and testify
← Back to Go Academy