英文:
Golang test coverage when test files outside package
问题
我正在尝试使用位于测试目录中的测试文件,获取处理器包中代码的适当覆盖量。我尝试了许多不同的-cover和-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
答案1
得分: 4
我找到了一个答案,这是我完成目标的方法:
go test -cover -coverpkg "./internal/processor" "./test"
根据 cmd/go, Testing Flags 的说明,该标志的用法是:
-coverpkg pattern1,pattern2,pattern3
应用于每个测试的覆盖率分析,匹配模式的包。**默认情况下,每个测试只分析被测试的包。**有关包模式的描述,请参阅 'go help packages'。设置-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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论