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

<p>There is the tool <a href="https://github.com/dave/courtney" rel="nofollow noreferrer">Courtney</a> which enforces 100% code coverage. This tool also allows you to comment on blocks of code which do not need to be covered. </p>

CC BY-SA 4.0
2019-01-27T17:31:30.900Z
I like this idea. [However the author of this tool has not been convinced yet to publish an executable](https://github.com/dave/courtney/issues/13), but perhaps my setup is wrong at the moment. Perhaps you could explain how you enabled this tool on your computer?
030
CC BY-SA 4.0
2019-01-28T19:03:52.720Z
@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`.
Jessie Barnett
CC BY-SA 4.0
2018-06-18T20:18:53.080Z
2018-06-18T20:18:53.080Z
Jessie Barnett
<p>Follow-up to <a href="https://stackoverflow.com/q/10516662/2777965">this Q&amp;A</a>.</p>

<p>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.</p>

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

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

<code-coverage><go>
What Golang function could be used to enforce a minimum code coverage and return an Exit1 if false?
030
# What Golang function could be used to enforce a minimum code coverage and return an Exit1 if false?

(Asked by: username_0 on 2018-05-27)

Follow-up to [this Q&A](https://stackoverflow.com/q/10516662/2777965).

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.

**Tags:** code-coverage, go


---

## 1 answers

### Answer by username_1 on 2018-06-18. Score: 2 | Accepted answer

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](https://github.com/dave/courtney) which enforces 100% code coverage. This tool also allows you to comment on blocks of code which do not need to be covered.

> **Comments:**
> **username_0**: I like this idea. [However the author of this tool has not been convinced yet to publish an executable](https://github.com/dave/courtney/issues/13), but perhaps my setup is wrong at the moment. Perhaps you could explain how you enabled this tool on your computer?  
> **username_1**: @username_0 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`.  

---

