1,022 B
1,022 B
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
$ mockery --all --outpkg pilgrim_mock --output ./internal/mocks
Run Tests
To run all tests, execute the following from the root directory
$ go test ./...
Coverage
To calculate test coverage, you have to run go test
with --cover
:
$ 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:
$ go tool cover -html=./coverage/cover.out
Alternatively, run the test_coverage.sh
script inside the bin
directory:
$ ./bin/test_coverage.sh