Follow-up to this Q&A.

How to ensure that a certain minimal code coverage is reached in Golang? E.g. if the CI runs, the build should fail if the code coverage is less than X percent.

In Java, one could use Jacoco and define a minimum code coverage. Other language like Python support minimum code coverage as well.

One option is to simply create a bash script that parsers the output of go test -cover, but I would like to know if there is a off the shelf solution.

1 Answer 1


There aren't any off the shelf solution currently that allows you to specify a variable number of code coverage percentage.

There is the tool Courtney which enforces 100% code coverage. This tool also allows you to comment on blocks of code which do not need to be covered.

  • I like this idea. However the author of this tool has not been convinced yet to publish an executable, but perhaps my setup is wrong at the moment. Perhaps you could explain how you enabled this tool on your computer?
    – 030
    Jan 27, 2019 at 17:31
  • @030 The assumption with the tool is you have Go installed on your system. If you do a go get for the tool, it will automatically install an executable of Courtney for you. Depending on how you have your $PATH variable set, you should be able to execute the command using either just courtney or $GOPATH/bin/courtney This is standard functionality for all go modules that have a package main. Jan 28, 2019 at 19:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.