登录
首页 >  Golang >  Go问答

go测试失败:使用-coverpkg参数时的解决方法

来源:stackoverflow

时间:2024-02-20 22:39:26 272浏览 收藏

从现在开始,努力学习吧!本文《go测试失败:使用-coverpkg参数时的解决方法》主要讲解了等等相关知识点,我会在golang学习网中持续更新相关的系列文章,欢迎大家关注并积极留言建议。下面就先一起来看一下本篇正文内容吧,希望能帮到你!

问题内容

我正在尝试获取项目中所有包的测试覆盖率。

当我执行以下命令时,测试已成功执行并报告覆盖率。

go test -cover ./...

但是当我使用 coverpkg=./... 参数执行 go test 时,所有测试都失败了

go test -cover -coverpkg=./... ./...

这是命令的示例输出

srimal@srimal-pc:~/projects/myproject$ go test -v -cover -coverpkg=./... ./...
go build a.abc.com/path/to/module/e2e: no non-test Go files in /home/srimal/projects/driver-selection-handler/e2e
?       a.abc.com/path/to/module      [no test files]
?       a.abc.com/path/to/module/app  [no test files]
?       a.abc.com/path/to/module/constrain    [no test files]
FAIL    a.abc.com/path/to/module/directionalhire [build failed]
?       a.abc.com/path/to/module/domain       [no test files]
FAIL    a.abc.com/path/to/module/durationmatrix [build failed]
FAIL    a.abc.com/path/to/module/durationmatrix/etaservice [build failed]
FAIL    a.abc.com/path/to/module/durationmatrix/roadmatrix [build failed]
2021/04/22 17:23:07 go-util/log: Cannot open config file  open config/logger.yaml: no such file or directory
testing: warning: no tests to run
PASS
coverage: 0.0% of statements in ./...
ok      a.abc.com/path/to/module/e2e  (cached)        coverage: 0.0% of statements in ./... [no tests to run]
?       a.abc.com/path/to/module/events       [no test files]
FAIL    a.abc.com/path/to/module/finance [build failed]
?       a.abc.com/path/to/module/internal     [no test files]
?       a.abc.com/path/to/module/internal/config      [no test files]
?       a.abc.com/path/to/module/internal/logger      [no test files]
?       a.abc.com/path/to/module/internal/metrics     [no test files]
?       a.abc.com/path/to/module/internal/profiling   [no test files]
?       a.abc.com/path/to/module/internal/schema      [no test files]
?       a.abc.com/path/to/module/internal/stream      [no test files]
FAIL    a.abc.com/path/to/module/location [build failed]
?       a.abc.com/path/to/module/logger       [no test files]
?       a.abc.com/path/to/module/metrics      [no test files]
FAIL    a.abc.com/path/to/module/selection [build failed]
FAIL    a.abc.com/path/to/module/store [build failed]
FAIL    a.abc.com/path/to/module/stream [build failed]
?       a.abc.com/path/to/module/stream/reg   [no test files]
FAIL    a.abc.com/path/to/module/weighted [build failed]

我使用的是 go 版本 1.15.6

有什么办法可以找到构建失败的原因吗?


正确答案


单独构建(或测试)包。

以上就是本文的全部内容了,是否有顺利帮助你解决问题?若是能给你带来学习上的帮助,请大家多多支持golang学习网!更多关于Golang的相关知识,也可关注golang学习网公众号。

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>