忽略课堂上的方法。 cobertura maven插件 [英] Ignore methods in class. cobertura maven plugin
问题描述
我有maven 3,cobertura maven插件2.51和一些classe。
我需要知道我班级的考试报道。但我不想测试setter / getters。所以我只想忽略它们。
I have maven 3, cobertura maven plugin 2.51 and some classe. I need to know test coverage of my class. But I don't want to test setters/getters. So I wand just to ignore them.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<formats>
<format>html</format>
<format>xml</format>
</formats>
<check>
<haltOnFailure>false</haltOnFailure>
<lineRate>55</lineRate>
<branchRate>60</branchRate>
<packageLineRate>60</packageLineRate>
<packageBranchRate>60</packageBranchRate>
<totalLineRate>60</totalLineRate>
<totalBranchRate>60</totalBranchRate>
</check>
<instrumentation>
<excludes>
<exclude>com/FileCopier*.*</exclude>
<exclude>com/FileCopierWithCamel*.*</exclude>
<exclude>com/Main*.*</exclude>
</excludes>
</instrumentation>
</configuration>
<executions>
<execution>
<goals>
<goal>clean</goal>
<goal>cobertura</goal>
<goal>check</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
然后我添加以下忽略块
<ignores>
<!-- Ignore all setter and getter methods in your classes -->
<ignore>com.*.set*</ignore>
<ignore>com.*.get*</ignore>
<ignore>com.MyClass.getName</ignore>
</ignores>
但似乎不起作用。
我找到了这个链接:
http://jira.codehaus.org/browse / MCOBERTURA-52
看起来这个问题大约是5岁。
我的问题是否有任何解决方案?
I found this link: http://jira.codehaus.org/browse/MCOBERTURA-52 Looks like this problem is about 5 year old. Is there any solution of my problem?
推荐答案
如果它只是关于getter和setter,你可以设置 ignoreTrival
开关:
If it's only about getters and setters, you could set the ignoreTrival
switch:
Cobertura Changelog -
新- ignoreTrivial
切换告诉Cobertura忽略覆盖率报告中的
:Getter方法只需
读取一个类字段;设置类字段的Setter方法;
仅设置类字段并调用超
类构造函数的构造函数。
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.
来源:是否仍然没有使用cobertura-maven-plugin忽略setter / getter(其他简单方法)的解决方案?
如果你想更具体地忽略方法,你也可以使用 ignoreMethodAnnotation
开关:
If you wish to ignore methods more specifically, you could also use the ignoreMethodAnnotation
switch:
Cobertura更改日志 -
新- ignoreMethodAnnotation
用于指定注释的开关,
当存在于方法,将导致Cobertura忽略覆盖率报告中的
方法。
Cobertura Changelog - New
--ignoreMethodAnnotation
switch used to specify an annotation that, when present on a method, will cause Cobertura to ignore the method in the coverage report.
文档: ignoreMethodAnnotation的文档(他们犯了一个小错误:他们定义 CoberturaIgnore
注释但是然后他们使用 CoverageIgnore
)
Documentation: Documentation of ignoreMethodAnnotation (they made a small mistake: they define the CoberturaIgnore
annotation but then they use CoverageIgnore
)
pom.xml中的示例
:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.7</version>
<configuration>
<instrumentation>
<ignoreTrivial>true</ignoreTrivial>
<ignoreMethodAnnotation>foo.bar.CoberturaIgnore</ignoreMethodAnnotation>
</instrumentation>
</configuration>
</plugin>
这篇关于忽略课堂上的方法。 cobertura maven插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!