Golang测试覆盖范围时测试文件外部包装

发布于 2025-01-22 20:29:33 字数 169 浏览 2 评论 0原文

我正在尝试使用测试目录中的测试文件在处理器软件包中获得正确的代码覆盖量。我尝试了许多组合和-Coverpkg的组合,并且无法使其正常工作。在单独的软件包/文件夹中将测试文件放入时可以做到吗?

.
├── internal
│   └── processor
└── test

I am trying to get the proper coverage amount of my code in the processor package using my test files that are in the test directory. I've tried numerous combinations of -cover and -coverpkg and cannot get it to work correctly. Can this be done while having the test files in separate package/folder?

.
├── internal
│   └── processor
└── test

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萌逼全场 2025-01-29 20:29:33

我跟踪了一个答案,这就是我能够实现目标的方式:

go test -cover -coverpkg "./internal/processor" "./test"

基于 cmd/ GO,测试标志,标志用法是:

-coverpkg模式1,dattery2,tatter2

在每个测试中应用覆盖范围分析以匹配模式。
默认值是每个测试仅分析要测试的软件包。
有关软件包模式的描述,请参见“ Go帮助包”。设置-Cover。

I tracked down an answer and this is how I was able to accomplish my goal:

go test -cover -coverpkg "./internal/processor" "./test"

Based on cmd/go, Testing Flags, the flag usage is:

-coverpkg pattern1,pattern2,pattern3

Apply coverage analysis in each test to packages matching the patterns.
The default is for each test to analyze only the package being tested.
See 'go help packages' for a description of package patterns. Sets -cover.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文