Correct testing method and documentation
This commit is contained in:
parent
4ec217f145
commit
888a87ab86
2 changed files with 8 additions and 17 deletions
|
@ -3,11 +3,9 @@ pushd $(dirname "$0")/.. # run from root dir
|
||||||
rm -rf ./coverage
|
rm -rf ./coverage
|
||||||
mkdir ./coverage/
|
mkdir ./coverage/
|
||||||
|
|
||||||
go build -cover -o target/pilgrim_coverage main.go
|
|
||||||
|
|
||||||
chmod 777 ./target/pilgrim_coverage
|
chmod 777 ./target/pilgrim_coverage
|
||||||
GOCOVERDIR=coverage ./target/pilgrim_coverage
|
go test --cover -coverpkg=./internal/pilgrim... -covermode=count -coverprofile=./coverage/cover.out ./...
|
||||||
|
|
||||||
go tool covdata percent -i=coverage
|
go tool cover -html=./coverage/cover.out
|
||||||
|
|
||||||
popd # switch back to dir we started from
|
popd # switch back to dir we started from
|
|
@ -22,25 +22,18 @@ $ go test ./...
|
||||||
|
|
||||||
### Coverage
|
### Coverage
|
||||||
|
|
||||||
To calculate test coverage, you have to build a special coverage binary and
|
To calculate test coverage, you have to run `go test` with `--cover`:
|
||||||
execute it. To do this, run the following in the root directory:
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ go build -cover -o target/pilgrim_coverage main.go
|
$ go test --cover -coverpkg=./internal/pilgrim... -covermode=count -coverprofile=./coverage/cover.out ./...
|
||||||
```
|
```
|
||||||
|
|
||||||
To calculate the coverage, execute the binary. You must setup the `GOCOVERDIR`
|
We only care about packages whose name starts with `pilgrim`. The rest are
|
||||||
environment variable in order to instruct the go coverage tool where to place
|
ignored.
|
||||||
the coverage data. The standard place for this in `pilgrim` is `coverage`:
|
|
||||||
```bash
|
|
||||||
$ chmod 777 ./target/pilgrim_coverage
|
|
||||||
$ GOCOVERDIR=coverage ./target/pilgrim_coverage
|
|
||||||
```
|
|
||||||
|
|
||||||
This will produce several files containing the coverage data. To turn this into
|
To display the coverage report, use the `cover` tool:
|
||||||
a human-readable format, use the go coverage tool:
|
|
||||||
```bash
|
```bash
|
||||||
$ go tool covdata percent -i=coverage
|
$ go tool cover -html=./coverage/cover.out
|
||||||
```
|
```
|
||||||
|
|
||||||
Alternatively, run the `test_coverage.sh` script inside the `bin` directory:
|
Alternatively, run the `test_coverage.sh` script inside the `bin` directory:
|
||||||
|
|
Loading…
Add table
Reference in a new issue