使用 Cobertura 从代码覆盖率中排除方法
有没有办法将代码排除在 Cobertura 覆盖率报告之外? 我们有一些方法不应包含在覆盖率报告中,因此不会降低覆盖率数字。
我知道Clover有这样的功能,但我还没有找到Cobertura的类似功能。
Is there a way to exclude code from inclusion into Cobertura coverage reports? We have some methods that should not be included in the coverage report and therefore not drive down the coverage numbers.
I know that Clover has such a functionality, but I have not found anything similar for Cobertura.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以从检测中排除类。 那么它们就不应该出现在报告中。 请参阅下面的排除语句。
您还可以忽略对某些方法的调用。 请参阅下面的忽略声明。
如果您使用的是 Maven,请参阅 maven 插件手册。
对于 ant,请参阅此。
You can exclude classes from instrumentation. Then they should not appear on reports. See exclude statements below.
You can also ignore calls to some methods. See ignore statement below.
If you are using maven, see maven plugin manual.
And for ant see this.
这让我头疼有一段时间了。
我的问题是我在报告部分而不是构建部分设置了 cobertura maven 插件。
如果您未在构建部分进行设置,则不会应用检测设置,从而排除类或包,因此请注意这一点。
This has been breaking my head for some time now.
My problem was that I had the cobertura maven plugin setup in the reporting section instead of the build section.
The instrumentation settings, and hence the excluding of classes or packages, won't be applied if you don't set it up on build section, so watch out for this.
请记住也要排除内部类。
我花了很长时间才注意到我缺少一个星号!
Remember to exclude inner classes too.
It took me ages to notice I was missing an asterisk!
Cobertura 目前没有提供这样的功能,Emma(我们使用的)也没有提供这样的功能,尽管它被列为即将推出的增强功能 - 尽管我相信是以排除规则的扩展形式而不是作为注释。
将那些难以触及的角落干净地遮盖起来会很方便,这样你就可以争取 100% 的成绩,而不会显得可笑。
我认为注释可能是一种更友好的方法,但它们应该被相当明确地命名并基于可接受的场景列表,因为我担心否则像“@ExcludeFromCoverage”这样的东西会被慷慨地添加。
Cobertura doesn't currently provide such a feature, and neither does Emma (which we use) although it is listed as a forthcoming enhancement - although in the form of an extension to the exclusion rules I believe rather than as an annotation.
Would be handy to cover off those few inaccessible corners cleanly so that you can strive for 100% without being ridiculous.
I think annotations would probably be a friendlier way to do it, but they ought to be fairly explicitly named and based on a list of acceptable scenarios as I fear otherwise something like '@ExcludeFromCoverage' would get added over generously.
从 2.0 开始,您可以编写自己的
@CoverageIgnore
注释。它将被 Cobertura 识别,它将避免考虑带注释的方法(据我所知,不适用于类)。
来源:https ://github.com/cobertura/cobertura/wiki/Coverage-Annotations
Since 2.0 you can write your own
@CoverageIgnore
annotation.It will be recognized by Cobertura, which will avoid considering annotated methods (does not work on classes as far as I know).
Source: https://github.com/cobertura/cobertura/wiki/Coverage-Annotations