是否仍然没有使用cobertura-maven-plugin忽略setter/getter(其他琐碎方法)的解决方案? [英] Is there still no solution for ignoring setter/getter (other trivial methods) with the cobertura-maven-plugin?
问题描述
有人找到了一种很好的解决方案来忽略琐碎的方法吗?
并不是真的可以选择使用Unitils
这样的自动化测试,因为如果仅测试getter/setter,代码覆盖率就不会提高!
Did someone find a good solution to ignore trivial methods?
Using some automated testing like Unitils
is not really an option, since the code-coverage should not go up if only getters/setters are tested!
使用 cobertrua-maven-plugin版本2.5.1 :
-)忽略方法不起作用<ignore>com.company.*.set*</ignore>
-)是否有人尝试添加
Using cobertrua-maven-plugin version 2.5.1:
-) ignore for methods does not work <ignore>com.company.*.set*</ignore>
-) did anyone try to include a patch like http://sourceforge.net/tracker/index.php?func=detail&aid=3010530&group_id=130558&atid=720017 into the maven-plugin?
-) anyone uses a different (better?) test-plugin?
对于每个get/set/is *方法普遍忽略也不是一个好方法,因为这些模式可以用在其他方法中,但可以使用类似getter/setter的方法.而且,应该容易猜到琐碎的吸气剂/设置器/构造函数.
A general ignore for every get/set/is* method is also not really a good way, since these patterns can be used in other methods but simle getter/setters. Also it should be easy to guess trivial getters/setters/constructors.
我知道以下问题:忽略类中的方法. cobertura maven插件,但是由于没有得到任何相关的答案,我想我再给它一个机会.
I know about the question: Ignore methods in class. cobertura maven plugin but since it did not get any relevant answers, I thought I give it another shot.
推荐答案
从Cobertura 2.0开始,有一个开关可以排除一些琐碎的方法:
Since Cobertura 2.0 there is a switch to exclude trivial methods:
[Cobertura Changelog] 新---ignoreTrivial开关,告诉Cobertura忽略 覆盖率报告中的以下内容:简单的Getter方法 阅读课程字段;用于设置类字段的设置方法; 仅设置类字段并调用父类的构造方法 类构造函数.
[Cobertura Changelog] New --ignoreTrivial switch that tells Cobertura to ignore the following in the coverage report: Getter methods that simply read a class field; Setter methods that set a class field; Constructors that only set class fields and call a super class constructor.
从2.6版开始,cobertura-maven-plugin使用Cobertura 2.x(请参阅发行版笔记).但是我还没有找到将开关传递到Maven插件配置的方法.
The cobertura-maven-plugin uses Cobertura 2.x since version 2.6 (see release notes). But i have not yet found a way to pass the switch to the maven plugin configuration.
尽管对此功能的状态似乎有些困惑(请参阅 Jira问题),标记确实适用于以下配置:
Although there seems to be some confusion about the state of this feature (see this Jira issue), the flag does seem to work with the following configuration:
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.6</version>
<configuration>
<instrumentation>
<ignoreTrivial>true</ignoreTrivial>
</instrumentation>
</configuration>
这篇关于是否仍然没有使用cobertura-maven-plugin忽略setter/getter(其他琐碎方法)的解决方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!