An open API service indexing awesome lists of open source software.

https://github.com/indeedeng/go-opine

go-opine is an opinionated tool to enforce minimum code coverage requirements for go projects, and supports writing coverage reports in junit xml or cobertura formats.
https://github.com/indeedeng/go-opine

golang testing-tools

Last synced: about 1 year ago
JSON representation

go-opine is an opinionated tool to enforce minimum code coverage requirements for go projects, and supports writing coverage reports in junit xml or cobertura formats.

Awesome Lists containing this project

README

          

go-opine
=========

[![Go Report Card](https://goreportcard.com/badge/oss.indeed.com/go/go-opine)](https://goreportcard.com/report/oss.indeed.com/go/go-opine)
[![Build Status](https://travis-ci.com/indeedeng/go-opine.svg?branch=master)](https://travis-ci.org/indeedeng/go-opine)
[![GoDoc](https://godoc.org/oss.indeed.com/go/go-opine?status.svg)](https://godoc.org/oss.indeed.com/go/go-opine)
[![NetflixOSS Lifecycle](https://img.shields.io/osslifecycle/indeedeng/go-opine.svg)](OSSMETADATA)
[![GitHub](https://img.shields.io/github/license/indeedeng/go-opine.svg)](LICENSE)

## Project Overview

go-opine is an opiniated way to run `go test ./... -race` and generate percent total
of lines covered by tests. By default go-opine exits successfully if at least 50% code
has test coverage, but this can be configured. go-opine tries to ignore and skip code
that was generated by tools when calculating test coverage (e.g
[minimock mocks](https://github.com/gojuno/minimock)). go-opine also supports outputting
test coverage reports in various formats, such as junit & cobertura.

## Getting Started

Run `go-opine test` to test for code coverage in the root of a go project. For example,
running in this repo produces the following output:

```
~/go-opine $
go-opine test
? indeed.com/gophers/go-opine [no test files]
ok indeed.com/gophers/go-opine/internal/run 0.039s
ok indeed.com/gophers/go-opine/internal/printing 0.019s
ok indeed.com/gophers/go-opine/internal/coverage 0.317s
ok indeed.com/gophers/go-opine/internal/junit 0.364s
ok indeed.com/gophers/go-opine/internal/gotest 1.572s
ok indeed.com/gophers/go-opine/internal/cmd 3.132s
Test coverage sufficient (85.4% >= 50.0%)
```

To generate a go coverage report, junit report, or corbertura report, see the usage info:
```
$ go-opine help test
test [-min-coverage ] [-junit ] [-xmlcov ] [-coverprofile ]:
Run Go tests in an opinionated way.
-coverprofile string
write Go coverprofile coverage
-junit string
write JUnit XML test results
-min-coverage float
minimum code test coverage to enforce (default 50)
-xmlcov string
write Cobertura XML coverage
```

#### Configuring minimum code coverage
By default go-opine requires 50% code coverage. This may not be adequate for every project,
but Indeed has found it to be a good minimum. For projects that want to enforce different test
coverage requirements, set the `-min-coverage` flag to the coverage percentage desired, between
`0` and `100`.

For example, to enforce a 75% code coverage requirement:
```
go-opine test -min-coverage 75
```

To disable code coverage requirements entirely, set `-min-coverage` to `0`.

#### go-opine is a Go tool

Since go-opine is typically a tool dependency (rather than a library dependency) you
can use the "tools.go" approach described in
[gotools](https://github.com/go-modules-by-example/index/tree/5ec250b4b78114a55001bd7c9cb88f6e07270ea5/010_tools)
and [go#25922](https://github.com/golang/go/issues/25922#issuecomment-451123151) to declare
the dependency.

If you are not using a `tools.go` you can `go get` go-opine and install it on your path.

## How To Contribute

We welcome contributions! Feel free to help make `go-opine` better.

### Process

- Open an issue and describe the desired feature / bug fix before making
changes. It's useful to get a second pair of eyes before investing development
effort.
- Make the change. If adding a new feature, remember to provide tests that
demonstrate the new feature works, including any error paths. If contributing
a bug fix, add tests that demonstrate the erroneous behavior is fixed.
- Open a pull request. Automated CI tests will run. If the tests fail, please
make changes to fix the behavior, and repeat until the tests pass.
- Once everything looks good, one of the indeedeng members will review the
PR and provide feedback.

### Maintainers

The `oss.indeed.com/go/go-opine` module is maintained by Indeed Engineering.

While we are always busy helping people get jobs, we will try to respond to
GitHub issues, pull requests, and questions within a couple of business days.

## Code of Conduct
This project is governed by the [Contributor Covenant v 1.4.1](CODE_OF_CONDUCT.md).

## License
This project uses the [Apache 2.0](LICENSE) license. (Update this and the LICENSE file if your project uses a different license.)