10

我一直在使用 Cobertura 插件来生成报告和检测(当然)。这是我面临的问题:

我无法让插件忽略我项目中特定类的报告生成。

PF 在 pom.xml 的相关摘录下方,我添加了忽略标记,但这只是忽略了被忽略类的检测。

我希望根本不生成特定项目的报告。

首先,由于我对 Maven 和 Conberture 的了解有限,我想知道这是否可能,如果是,那么我需要在 pom.xml 中进行哪些更改。

pom.xml

<report>
    <!-- other plugins exist but are not important to be listed here I guess -->   
    <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
            <skipTests>false</skipTests>
            <systemProperties>
                <property>
                <name>net.sourceforge.cobertura.datafile</name>
                <value>target/cobertura/cobertura.ser</value>
                </property>
            </systemProperties>
        </configuration>
    </plugin>
    <!-- The following is the plugin for cobertura, which takes care of integration and report generation-->
    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>cobertura-maven-plugin</artifactId>
        <configuration>
            <check>
                <branchRate>50</branchRate>
                <lineRate>50</lineRate>
                <haltOnFailure>true</haltOnFailure>
                <totalBranchRate>50</totalBranchRate>
                <totalLineRate>50</totalLineRate>
                <packageLineRate>50</packageLineRate>
                <packageBranchRate>50</packageBranchRate>
            </check>
            <instrumentation>
                <ignores>
                  <ignore>deshaw.dportal.alert.*</ignore>
                  <ignore>deshaw.dportal.atc.*</ignore>
                  <ignore>deshaw.dportal.basket.*</ignore>
                  <ignore>deshaw.dportal.fcs.*</ignore>
                  <ignore>deshaw.dportal.event.*</ignore>
                  <ignore>deshaw.dportal.filings.*</ignore>
                  <ignore>deshaw.dportal.glg.*</ignore>
                  <ignore>deshaw.dportal.icp.*</ignore>
                </ignores>
            </instrumentation>
        </configuration>
    </plugin>
</report>

编辑:

这是我的目录结构:

module
|
|-apps
|    |-alert
|    |    |-src
|    |    |-target
|    |    |-pom.xml
|    |-------------------
|    |-company
|    |    |-src
|    |    |-target
|    |    |-pom.xml
|-----------------------
|-jobs
|    |-job1
|    |    |-src
|    |    |-target
|    |    |-pom.xml
|    |-job2
|    |    |-src
|    |    |-target
|    |    |-pom.xml

我在 module/pom.xml 中尝试了以下内容

<instrumentation>
    <excludes>
        <exclude>**/apps/*.*</exclude>
    </excludes>
</instrumentation>

我仍然在警报和公司目录中生成报告。

可能排除正则表达式不正确?

4

5 回答 5

4

Cobertura maven 插件不尊重报告生成的排除和忽略。不过,它是为了检测而这样做的。

已知错误报告在:http: //jira.codehaus.org/browse/MCOBERTURA-52

于 2011-03-15T05:52:56.637 回答
4

您可以exclude通过将<plugin>块从<reporting>块移动到您<build>pom.xml.

于 2011-10-18T13:14:35.167 回答
3

我遇到了类似的问题,发现了一个非常有用的教程:http ://www.java-tutorial.ch/software-testing/maven-cobertura

该解决方案与 rdvdijk 发布的答案非常接近。插件信息应该在构建部分和报告部分中。但是排除信息应该放在 pom 的构建部分。

于 2012-12-28T10:48:02.243 回答
1

使用排除 io 忽略。
这就是我从 cobertura 中排除特定类的方式:

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.4</version>
<configuration>
    <instrumentation>
        <excludes>
            <exclude>com/bnpp/ecom/**/*Test.class</exclude>
            <exclude>com/lrc/web/WicketApplication.class</exclude>
            <exclude>com/lrc/service/HeartBeatWebServiceMock.class</exclude>
        </excludes>
    </instrumentation>
</configuration>

Greetz,
Stijn

于 2011-03-07T14:42:11.210 回答
0

在将 cobertura-maven-plugin 版本从 2.6 更改为 2.4 后,我可以通过忽略项目中的 *Test 文件来成功生成 cobertura 覆盖率报告(如上述评论中的 Stjin geukens 所述)。

请在下面找到完整的 Maven 插件详细信息:

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>cobertura-maven-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <instrumentation>
                        <excludes>
                            <exclude>com/services/impl/*Test.class</exclude>
                            <exclude>com/exceptions/*Test.class</exclude>
                            <exclude>com/services/*Test.class</exclude>
                            <exclude>com/utils/*Test.class</exclude>
                        </excludes>
                    </instrumentation>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>cobertura</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

PS:我不确定2.6版本的插件有什么问题

于 2015-09-01T19:08:07.067 回答