简体   繁体   English

如何在HTML覆盖率报告中包含* _test.go文件

[英]How to include *_test.go files in HTML coverage reports

I would like to know if there is a way that I can generate an HTML coverage report that also includes statements covered on the tests themselves. 我想知道是否有一种方法可以生成HTML覆盖率报告,其中还包括测试本身覆盖的语句。

Regarding the merits of doing such a thing, I would like to see that my tests are as useful as the rest of my code. 关于这样做的好处,我希望看到我的测试与其余代码一样有用。 I've become accustomed to including my test code coverage in python and this is something I find helpful. 我已经习惯于将测试代码覆盖范围包括在python中,这对我有所帮助。

Update for clarification: 更新说明:

People seem to think I'm talking about testing my tests. 人们似乎以为我在谈论测试测试。 I'm not. 我不是。 I just want to see that the statements in my tests are definitely being hit in the HTML coverage report. 我只是想看看我的测试中的语句肯定在HTML覆盖率报告中受到了打击。 For example, code coverage on a function in my application might show me that everything's been hit, but it won't necessarily show me that every boundary has been tested. 例如,应用程序中某个函数的代码覆盖范围可能会告诉我所有内容都已被击中,但不一定表明每个边界都已经过测试。 Seeing statements lit up in my test sources show me that I wrote my test well enough. 看到测试源中出现的陈述表明我编写的测试足够好。 Yes, better factored code shouldn't be so complex as to need that assurance, but sometimes things just aren't better. 是的,分解更好的代码不应太复杂以至于不需要那种保证,但是有时候情况并没有更好。

I'm not sure I understand the reasoning behind this. 我不确定我是否理解这背后的原因。

Unit tests, especially in Go, should be simple and straight-forward enough that by just reading them you should be able to spot if a statement is useless. 单元测试,尤其是Go语言中的单元测试,应该足够简单明了,以至于只要阅读它们,就可以发现一条语句是否无用。

If that is not the case, maybe you are implementing your unit tests in a way that is too complicated? 如果不是这种情况,也许您正在以过于复杂的方式实施单元测试?

If that is the case, I can recommend checking table-driven tests for most cases (not suited for most concurrency-heavy code or methods that depend a lot on manipulating the state, though) as well as trying out TDD (test-driven development). 如果是这种情况,我建议您在大多数情况下建议检查表驱动的测试 (尽管不适合大多数并发性高的代码或很大程度上依赖于操纵状态的方法),还建议您尝试使用TDD(测试驱动的开发) )。

By using TDD, instead of building your tests in order to try to cover all of your code, you would be writing simple tests that simply validate the specs of your code. 通过使用TDD,您可以编写简单的测试来验证代码规范,而不是构建测试来覆盖所有代码。

You don't write tests for your tests. 您不会为测试编写测试。 Where does it end at that point if you do? 如果这样做的话,到那时候结束呢? Those tests for tests aren't covered. 这些测试不包括在内。 You'll need to write tests for your tests for your tests. 您需要为测试编写测试。 But wait! 可是等等! Those tests for your tests for your tests don't have coverage so you better write tests for your tests for your tests for your tests. 这些测试的测试没有涵盖范围,因此您最好为自己的测试编写测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM