combined-coverage-demo

Demonstrate combining code coverage from unit tests and integrations into a single profile.

Purpose

Go 1.20 adds support for collecting code coverage during integration tests by creating binaries ready to collect coverage.

This demo shows the following:

  1. Collecting code coverage for unit tests in binary format instead of traditional text format
  2. Building a binary ready to collect coverage
  3. Executing the binary in a successful manner
  4. Executing the binary in a manner that will take a failure path
  5. Showing the coverage from unit tests alone
  6. Showing the coverage from integration tests alone
  7. Showing the combined coverage of unit tests and integration tests
  8. Converting binary coverage report to text format
  9. 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.

Usage

  1. Install Go 1.20 RC2 or newer
  2. Run ./get-cover.sh