CoderSchmoder
CoderSchmoder

Reputation: 183

Golang test coverage when test files outside package

I am trying to get the proper coverage amount of my code in the processor package using my test files that are in the test directory. I've tried numerous combinations of -cover and -coverpkg and cannot get it to work correctly. Can this be done while having the test files in separate package/folder?

.
├── internal
│   └── processor
└── test

Upvotes: 5

Views: 2502

Answers (1)

CoderSchmoder
CoderSchmoder

Reputation: 183

I tracked down an answer and this is how I was able to accomplish my goal:

go test -cover -coverpkg "./internal/processor" "./test"

Based on cmd/go, Testing Flags, the flag usage is:

-coverpkg pattern1,pattern2,pattern3

Apply coverage analysis in each test to packages matching the patterns. The default is for each test to analyze only the package being tested. See 'go help packages' for a description of package patterns. Sets -cover.

Upvotes: 5

Related Questions