pilgrim/docs/TESTS.md

43 lines
No EOL
1,022 B
Markdown

# Writing & Maintaining Tests
Pilgrim's tests are written using the testify framework and mockery.
### Generate Mocks
The below command, when executed from the project root, will generate mocks for
all interfaces in all packages of the project, and put them in the `mocks`
directory, under the `pilgrim_mock` package
```bash
$ mockery --all --outpkg pilgrim_mock --output ./internal/mocks
```
### Run Tests
To run all tests, execute the following from the root directory
```bash
$ go test ./...
```
### Coverage
To calculate test coverage, you have to run `go test` with `--cover`:
```bash
$ go test --cover -coverpkg=./internal/pilgrim... -covermode=count -coverprofile=./coverage/cover.out ./...
```
We only care about packages whose name starts with `pilgrim`. The rest are
ignored.
To display the coverage report, use the `cover` tool:
```bash
$ go tool cover -html=./coverage/cover.out
```
Alternatively, run the `test_coverage.sh` script inside the `bin` directory:
```bash
$ ./bin/test_coverage.sh
```