From b7dbeac2765f66cfaf4c38b72cfa62ace706df6a Mon Sep 17 00:00:00 2001 From: Robert Pirtle Date: Thu, 21 Sep 2023 12:14:41 -0700 Subject: [PATCH] add test coverage reporting --- .gitignore | 2 ++ DEVELOPMENT.md | 8 ++++++++ Makefile | 14 ++++++++++---- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 395f9e9..bb30b67 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,8 @@ kava-proxy-service # Output of the go coverage tool, specifically when used with LiteIDE *.out +# coverage report converted to HTML +cover.html # Dependency directories (remove the comment below to include it) # vendor/ diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 342bb89..e5a3ac2 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -96,6 +96,14 @@ The e2e tests won't pass if the proxy service and it's dependencies aren't fully make ready e2e-test ``` +## Test Coverage Report + +The test commands `make test`, `make unit-test`, and `make e2e-test` generate a `cover.out` raw test coverage report. The coverage can be converted into a user-friendly webpage: + +```bash +make show-coverage +``` + ### Running specific tests only Often during iterative development you want to run only a specific test (or group of tests), the `it` target will allow you to do just that: diff --git a/Makefile b/Makefile index 382b0e7..b230e5d 100644 --- a/Makefile +++ b/Makefile @@ -37,22 +37,28 @@ publish: lint .PHONY: unit-test # run all unit tests unit-test: - go test -count=1 -v -cover --race ./... -run "^TestUnitTest*" + go test -count=1 -v -cover -coverprofile cover.out --race ./... -run "^TestUnitTest*" .PHONY: e2e-test # run tests that execute against a local or remote instance of the API e2e-test: - go test -count=1 -v -cover --race ./... -run "^TestE2ETest*" + go test -count=1 -v -cover -coverprofile cover.out --race ./... -run "^TestE2ETest*" .PHONY: it # run any test matching the provided pattern, can pass a regex or a string # of the exact test to run it : lint - go test -count=1 -v -cover --race ./... -run=".*${p}.*" + go test -count=1 -v -cover -coverprofile cover.out --race ./... -run=".*${p}.*" + +.PHONY: show-coverage +# convert test coverage report to html & open in browser +show-coverage: + go tool cover -html cover.out -o cover.html && open cover.html .PHONY: test # run all tests -test: unit-test e2e-test +test: + go test -count=1 -v -cover -coverprofile cover.out --race ./... .PHONY: up # start dockerized versions of the service and it's dependencies