Go coverage with external tests
The Go test coverage implementation is innovative as it allows setting a bit in a coverage bitmap when each code portion is executed. However, there's no straightforward way to obtain coverage data for tests run against the main version of a program. A workaround involves creating a dummy test that executes main(), compiling a binary with go test -c -cover and running only that test instead of the regular binary. This method has been used in RRDNS, a custom Go DNS server. To collect coverage information, run the test battery as usual and use gocovmerge to merge coverage profiles for unit tests.
Company
Cloudflare
Date published
Jan. 19, 2016
Author(s)
Filippo Valsorda
Word count
357
Language
English
Hacker News points
9