Test coverage in Go, the whole package
summary
Explains exactly how Go computes coverage by rewriting source and adding a generated counter struct, shows the coverage profile format (coverage.out) and an awk script that aggregates statements to get module-level coverage, and demonstrates surprising examples: calculator package reports 16.7% (6 statements, 1 executed), module aggregate first reads 30.77% then drops to 21.05% after adding an empty _test file, generated files count against coverage, nested subpackages are not auto-aggregated, and using -covermode=count shows execution counts (e.g. 3 hits).
AI-written summary · about
chapters (16)
- 0:00Start
- 9:25Step 1: rewriting the code (6:6)
- 11:43Step 3: dump the statistics (2:2)
- 15:08Module level coverage (5:6)
- 18:09Module coverage: package with no tests (1:3)
- 18:57Module coverage: package with no tests (2:3)
- 20:18Module coverage: package with no tests (3:3)
- 21:21Module coverage: nested sub-package
- 24:51Module coverage:go generated code
- 27:19Module coverage: integration testing (1:5)
- 28:07The mod7 module (2:2)
- 28:41Module coverage: integration testing (4:5)
- 32:32Module coverage: integration testing (5:5)
- 35:16Cover HTML output (1:3)
- 37:02Use your IDE (1:3)
- 37:45Coverage: mode (1:2)








