【发布时间】:2021-11-04 04:36:46
【问题描述】:
我只有 24 小时使用 Go,所以我对此非常陌生。
我正在尝试进行完整的测试转换,但是当我运行时
go test -cover new-project/anto/... .
在 new-project/anto/mon 中显示我有 51.8% 的覆盖率,但实际上我有更多的覆盖率,因为在 new-project/anto 中测试了一些测试/integration 我有一个测试文件,我导入 new-project/anto/mon 进行测试。
问题是,当我阅读 Golang 时,仅在测试位于同一文件夹中时才进行测试,但具有单独的文件并不能正确检测到它。
我想知道是否有办法获得全面覆盖。
go test -cover new-project/anto/... .
? new-project/anto/ [no test files]
ok new-project/anto/conf 6.060s coverage: 73.1% of statements
ok new-project/anto/integration 43.309s coverage: [no statements]
? new-project/anto/integration/conf [no test files]
? new-project/anto/integration/mocks [no test files]
? new-project/anto/integration/utils [no test files]
ok new-project/anto/logs 0.024s coverage: 70.5% of statements
ok new-project/anto/metric 0.012s coverage: 59.0% of statements
ok new-project/anto/mon 1.612s coverage: 51.8% of statements
? new-project/anto/anotherComponents [no test files]
做了一些研究,我发现了一个 go-acc 插件,它可以验证所有的包,奇怪的是 mon 原来是 51.8%,现在变成了 29.8%。
go-acc new-project/anto/... .
? new-project/anto/ [no test files]
ok new-project/anto//conf 5.030s coverage: 73.1
ok new-project/anto//integration 43.117s coverage: 73.5
? new-project/anto//integration/conf [no test files]
? new-project/anto//integration/mocks [no test files]
? new-project/anto//integration/utils [no test files]
ok new-project/anto//logs 0.008s coverage: 22.3
ok new-project/anto//metric 0.020s coverage: 59.0
ok new-project/anto//mon 1.460s coverage: 29.8
? new-project/anto//anotherComponents [no test files]
? new-project/anto/ [no test files]
【问题讨论】:
标签: go testing integration-testing