dongtan7418 2018-03-26 10:33
浏览 542

如何在自定义文件夹中使用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?

  • 写回答

2条回答 默认 最新

  • dongzanghua8422 2019-05-07 16:36
    关注

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

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

    评论

报告相同问题?

悬赏问题

  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题