忽略课堂上的方法.cobertura maven插件

Dmi*_*voi 3 java testing cobertura maven

我有maven 3,cobertura maven插件2.51和一些classe.我需要知道我班级的考试报道.但我不想测试setter/getters.所以我只想忽略它们.

 <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>
Run Code Online (Sandbox Code Playgroud)

然后我添加以下ignore块

 <ignores>
                            <!-- Ignore all setter and getter methods in your classes -->
                            <ignore>com.*.set*</ignore>
                            <ignore>com.*.get*</ignore>
                            <ignore>com.MyClass.getName</ignore>
                        </ignores>
Run Code Online (Sandbox Code Playgroud)

但似乎它不起作用.

我找到了这个链接:http: //jira.codehaus.org/browse/MCOBERTURA-52 看起来这个问题大约是5岁.我的问题有什么解决方案吗?

bou*_*mbh 6

如果它只是关于getter和setter,你可以设置ignoreTrival开关:

Cobertura Changelog - 新的 --ignoreTrivial开关告诉Cobertura忽略覆盖率报告中的以下内容:Getter方法只读取一个类字段; 设置类字段的Setter方法; 仅设置类字段并调用超类构造函数的构造函数.

来源:是否仍然没有使用cobertura-maven-plugin忽略setter/getter(其他简单方法)的解决方案?

如果您希望更具体地忽略方法,您还可以使用ignoreMethodAnnotation开关:

Cobertura Changelog - 用于指定注释的新 --ignoreMethodAnnotation开关,当存在于方法上时,将导致Cobertura忽略coverage报告中的方法.

文档:ignoreMethodAnnotation的文档(他们犯了一个小错误:他们定义了CoberturaIgnore注释但他们使用了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>
Run Code Online (Sandbox Code Playgroud)