如何在GO中检测分离文件夹的代码覆盖率? [英] How to detect code-coverage of separated folders in GO?

查看:186
本文介绍了如何在GO中检测分离文件夹的代码覆盖率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目结构

stuff / stuff.go->包:stuff

test / stuff / stuff_test.go->包:test

尽管stuff_test从stuff.go执行代码,但它显示了

覆盖率:语句的0.0%



我使用了
去测试-cover

如果我移动我的* _test.go进入程序的文件夹时,它工作正常。

也许我对项目结构的方法设计不周全/符合标准?

My project-structure
stuff/stuff.go -> package: stuff
test/stuff/stuff_test.go -> package: test
Although stuff_test executes code from stuff.go it shows
coverage: 0.0% of statements

I used go test -cover
If I move my *_test.go to the stuff-folder of the program it is working fine.
Or perhaps my approach of the project-structure is not well designed/go-conform?

推荐答案

不直接支持跨程序包测试覆盖率,但是一些人已经构建了包装程序来合并各个覆盖率配置文件。

Cross-package test coverage is not directly supported, but several people have built wrappers to merge individual coverage profiles.

有关此问题的悠久历史,请参见问题#6909 。并请参阅 gotestcover 进行合并的示例工具。还有 gocovmerge 。我建立了自己的版本,因此没有尝试过任何版本,但是我确信它们都可以像我的一样工作,并且我的工作正常。

See Issue #6909 for the long history on this. And see gotestcover for an example tool to do the merging. There's also gocovmerge. I built my own version, so I haven't tried any of these, but I'm sure they all work like mine, and mine works fine.

我的感觉是这只是一个问题,没有人为它编写过一个真正令人信服的变更清单,而且对于核心维护者而言还没有那么重要,因此尚未得到解决。它确实提出了一些可能会破坏现有测试的极端情况,因此,对我们大多数人有效的快速hack并没有被接受。但是我没有看到任何讨论暗示核心维护者会积极反对此功能。

My sense is that this is just an issue that no one has written a really compelling changelist for, and hasn't been that important to the core maintainers, so it hasn't been addressed. It does raise little corner cases that might break existing tests, so the quick hacks that work for most of us haven't been accepted as-is. But I haven't seen any discussion suggesting the core maintainers actively object to this feature.

这篇关于如何在GO中检测分离文件夹的代码覆盖率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆