~/talk

Test coverage in Go, the whole package

Talkat GopherCon UK 2021 · 2021-10-25..10-27· [testing]
slides:none on file

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

  1. 0:00Start
  2. 9:25Step 1: rewriting the code (6:6)
  3. 11:43Step 3: dump the statistics (2:2)
  4. 15:08Module level coverage (5:6)
  5. 18:09Module coverage: package with no tests (1:3)
  6. 18:57Module coverage: package with no tests (2:3)
  7. 20:18Module coverage: package with no tests (3:3)
  8. 21:21Module coverage: nested sub-package
  9. 24:51Module coverage:go generated code
  10. 27:19Module coverage: integration testing (1:5)
  11. 28:07The mod7 module (2:2)
  12. 28:41Module coverage: integration testing (4:5)
  13. 32:32Module coverage: integration testing (5:5)
  14. 35:16Cover HTML output (1:3)
  15. 37:02Use your IDE (1:3)
  16. 37:45Coverage: mode (1:2)
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.