Demonstrate combining code coverage from unit tests and integrations into a single profile.
Go 1.20 adds support for collecting code coverage during integration tests by creating binaries ready to collect coverage.
This demo shows the following:
- Collecting code coverage for unit tests in binary format instead of traditional text format
- Building a binary ready to collect coverage
- Executing the binary in a successful manner
- Executing the binary in a manner that will take a failure path
- Showing the coverage from unit tests alone
- Showing the coverage from integration tests alone
- Showing the combined coverage of unit tests and integration tests
- Converting binary coverage report to text format
- Displaying the combined coverage using the text format
Steps using the binary coverage report using go tool covdata
, while steps
consuming the text format use go tool cover
. Both of these can be seen in get-cover.sh.
- Install Go 1.20 RC2 or newer
- Run
./get-cover.sh