如何从三叶草覆盖率报告中排除方法(哈希码和等于)?
我想从 clover 报告中排除 hashCode
和 equals
。
一些配置示例会很好。
I would like to exclude hashCode
and equals
from clover report.
Some configuration example would be nice.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我谨建议您实际测试这些方法而不是避免它们。如果不符合规范,可能会出现严重的错误。我也曾在编写不佳的
hashCode
和equals
方法中遇到过 NPE 和其他问题。这是一个很好的链接,其中包含多种测试方法的方法:我们使用以下可以通过单元测试扩展的
LocalEqualsHashCodeTest
:然后定义一个
createInstance()
方法它返回您的类的实例和createNotEqualInstance()
方法,该方法返回不等于第一个实例的另一个实例。I would respectfully suggest that you actually test these methods instead of avoiding them. Serious bugs can occur if they are not consistent with specifications. I've encountered NPEs and other problems in poorly written
hashCode
andequals
methods as well. Here's a great link with a number of ways that you can test your methods:We use the following
LocalEqualsHashCodeTest
which can be extended by a unit test:You then define a
createInstance()
method which returns an instance of your class and acreateNotEqualInstance()
method which returns another instance that is not equal to the first one.您必须执行两个步骤:
1) 在中定义方法上下文。包含要匹配的方法的正则表达式的任务,例如:
2) 在中定义应从报告中排除哪些方法上下文。任务
更多信息:
You have to do two steps:
1) Define method contexts in the <clover-setup> task containing regular expressions for methods you want to match, for example:
2) Define which method contexts shall be excluded from the report in the <clover-report> task
More information: