【问题标题】:`go test ./... -coverprofile=coverage.out` does not report everything? [duplicate]`go test ./... -coverprofile=coverage.out` 没有报告所有内容? [复制]
【发布时间】:2020-02-13 07:20:43
【问题描述】:

我正在尝试对项目运行测试覆盖率报告。当我在项目的根目录运行 go test ./... -count=1 时,它会列出所有正在测试的命名空间。对于这个项目,它看起来像这样:

?       some/namespace  [no test files]
?       some/namespace/A    [no test files]
?       some/namespace/B    [no test files]
ok      some/namespace/util 0.260s  coverage: 100.0% of statements

但是,当我运行 go test ./... -coverprofile=coverage.out 时,它只会为我的 util 包生成行,并且底部的最后一行显示了 100% 的测试覆盖率。虽然我确实覆盖了 100% 的命名空间,但我希望如果我要求整个项目的测试覆盖率,总百分比将包括没有测试的包。

我如何才能为我的整个项目获得适当百分比的测试覆盖率?

【问题讨论】:

    标签: unit-testing go


    【解决方案1】:

    尝试使用其他标志:

    去测试 ./... -covermode=atomic -coverprofile=coverage.out -coverpkg=./...

    【讨论】:

      猜你喜欢
      • 2013-11-04
      • 1970-01-01
      • 1970-01-01
      • 2012-04-07
      • 2023-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多