As part of a Go
unit testing CI job, we can generate code coverage statistics. For Gitlab to display them, we must provide appropriate output from the job’s script
commands (stdout). Below is a sample CI test job:
On line 5 we run the go test
command and specify that we would like to generate coverage profile and save it in a file called coverage.out
On line 6 we use the go tool cover
command to generate (stdout) output broken down by function. Example output is shown below:
|
|
After the script
commands are executed, we can tell Gitlab how to parse the output and extract the test coverage value.
The value we want to display as code coverage percentage is 65.3%
. The regular expression to use for that is:
|
|
The regular expression can be set in Settings >> CI/CD >> General Pipelines >> Test coverage parsing
. For more complete information, check the Gitlab guide.