如何在自定义文件夹中使用go test生成多个软件包的覆盖率?

We have following project structure:

├── Makefile
├── ...
├── src
│   ├── app
│   │   ├── main.go
│   │   ├── models
│   │       ├── ...
│   │       └── dao.go
│   │   ├── ...
│   │   └── controllers
│   │       ├── ...
│   │       └── pingController.go
│   └── test
│       ├── all_test.go
│       ├── ...
│       └── controllers_test.go
└── vendor
    └── src
        ├── github.com
        ├── golang.org
        └── gopkg.in

I want to measure coverage of packages in src/app by tests in src/test. And currently generating coverage profile by running custom script that runs coverage for each package in app and then merges all coverage profiles into one file. Recently I heard that in go1.10 we are able to generate coverage for multiple packages.

So I tried to replace that script with oneliner, and tried running

GOPATH=${PROJECT_DIR}:${PROJECT_DIR}/vendor go test -covermode count -coverprofile cover.out -coverpkg all ./src/test/...

It gives me "ok test 0.475s coverage: 0.0% of statements in all"

When I do

cd src/test/
GOPATH=${PROJECT_DIR}:${PROJECT_DIR}/vendor go test -covermode count -coverprofile cover.out -coverpkg all

Logs show that specs are runned and tests are successfull, but still I have "coverage: 0.0% of statements in all" and empty cover.out.

What am I missing to properly compute coverage of packages in app by tests in test?

You can't with the current state of go test but you can always use third party scripts.

https://github.com/grosser/go-testcov

使用参数 -coverpkg=../app/... | ./app/...