0

I have been writing an rest service I have the following structure

/controllers
/domain/dao
/services

after writing a lot of tests for each individual package with mocks for each stage, I thought it would be quicker to just write tests against the controller and mock the database, so in that I know the /domain/dao layer is being called.

My problem now is when I run code coverage I do not get the coverage for my /service or the /domain/dao even though I know the code is being called

Any ideas on how to get my code coverage on all files?

Charles Bryant
  • 995
  • 2
  • 18
  • 30

1 Answers1

4

You can try the flag -coverpkg

go test --cover -coverpkg=./services  ./... -coverprofile=cover.out

To check all the packages in the folder /services as well, you can try:

go test --cover -coverpkg=./services/...  ./... -coverprofile=cover.out

Just a side note - I usually add -covermode=count

go test --cover -covermode=count -coverpkg=./services/...  ./... -coverprofile=cover.out

Then, you can use go tool to see it as html:

go tool cover -html=cover.out
oren
  • 3,159
  • 18
  • 33