Reputation: 737
I have a test in my application but my test coverage is saying that I have 0% coverage.
Below is the make command that I am using:
# TODO: FIX this it works if I go into the src directory and manually run this command but not from makefile
coverage:
cd src/test && \
echo $(pwd) && \
go test -mod=mod -coverprofile=coverage.out -coverpkg=./... ./... && go tool cover -func=coverage.out
If I run my test using IntelliJ IDE like this (see picture below), I get a coverage of 2.2%.
What should I do to my makefile command for my gocov to recognize my test case?
Upvotes: 1
Views: 458
Reputation: 737
The fix was pretty simple, all I had to do was add another .
in front of the slash so instead of -coverpkg=./... ./...
I had to use -coverpkg=./... ./...
. Below is my make command, I also added gocov reporting.
coverage: coverage-tools
cd src/test && \
go test -mod=mod -coverprofile=coverage.out -coverpkg=../... ../... && \
mkdir -p $(REPORT_DIR) && \
cp coverage.out $(REPORT_DIR)/ && \
$(GOPATH)/bin/gocov convert $(REPORT_DIR)/coverage.out | \
$(GOPATH)/bin/gocov-html > $(REPORT_DIR)/coverage.html
rm ./src/test/coverage.out
Upvotes: 0