pilgrim/docs/TESTS.md

50 lines
1.3 KiB
Markdown
Raw Normal View History

2025-03-15 19:36:11 +02:00
# 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
2025-03-18 21:45:07 +02:00
$ mockery --all --outpkg pilgrim_mock --output ./internal/mocks
2025-03-15 19:36:11 +02:00
```
#### Run Tests
To run all tests, execute the following from the root directory
```bash
2025-03-18 21:45:07 +02:00
$ go test ./...
```
#### Coverage
To calculate test coverage, you have to build a special coverage binary and
execute it. To do this, run the following in the root directory:
```bash
$ go build -cover -o target/pilgrim_coverage main.go
```
To calculate the coverage, execute the binary. You must setup the `GOCOVERDIR`
environment variable in order to instruct the go coverage tool where to place
the coverage data. The standard place for this in `pilgrim` is `coverage`:
```bash
$ chmod 777 ./target/pilgrim_coverage
$ GOCOVERDIR=coverage ./target/pilgrim
```
This will produce several files containing the coverage data. To turn this into
a human-readable format, use the go coverage tool:
```bash
$ go tool covdata percent -i=coverage
```
Alternatively, run the `test_coverage.sh` script inside the `bin` directory:
```bash
$ ./bin/test_coverage.sh
2025-03-15 19:36:11 +02:00
```