8.5 Test Coverage

Coverage measures how much of your code is tested. It matters because it helps identify untested code, guides testing efforts, and ensures critical paths are tested.

Measuring coverage

go test -cover                    # Show coverage percentage
go test -coverprofile=coverage.out  # Generate coverage file
go tool cover -html=coverage.out    # View in browser

Coverage goals

100% coverage isn't always the goal. Focus on testing critical paths, edge cases, and error conditions. Some code (like simple getters/setters) may not need tests.