如何排除/忽略类/包被maven-emma插件检测?

时间:2014-03-18 07:38:50

标签: java spring hibernate maven

我正在研究基于java / spring / hibernate / Maven的项目。我有一些单元测试,我已经为代码覆盖率报告配置了emma pulign。 我添加了" emma-maven-plugin"在POM.xml文件中生成代码覆盖率报告。

<!-- Emma profile -->
    <profile>
        <id>EMMA</id>
        <activation>
            <activeByDefault>false</activeByDefault>
        </activation>
        <build>
            <finalName>BuildForEmma</finalName>
            <pluginManagement>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>emma-maven-plugin</artifactId>
                        <version>1.0-alpha-3</version>
                        <configuration>
                            <inherited>true</inherited>
                            <forkMode>once</forkMode>
                            <reportFormat>xml</reportFormat>
                            <classesDirectory>${project.build.directory}/generated-classes/emma/classes</classesDirectory>
                            </configuration>
                        <executions>
                            <execution>
                                <phase>process-classes</phase>
                                <goals>
                                    <goal>emma</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </pluginManagement>
        </build>
    </profile>
</profiles>

当我运行&#34; mvn clean install emma:emma&#34;等命令时。代码覆盖率艾玛报告成功处理。但是在代码覆盖率报告中,有许多类和包未通过我的测试用例覆盖,因此我需要排除并忽略这些包/类以改善代码覆盖率结果。

为此,我尝试在emma puling中添加此条目。

<instrumentation>
<ignores>
<ignore>com.exam.generated.ceq.*</ignore>
<ignore>com.exam.activities.*</ignore>
<ignore>com.exam.activities.cdr.generated.*</ignore>
<ignore>com.exam.admin.*</ignore>
</ignores>
</instrumentation> 

但它不起作用,我也检查了很多关于链接但不能获得成功。任何帮助将不胜感激。感谢。

1 个答案:

答案 0 :(得分:1)

您可以在插件的配置中添加排除列表:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>emma-maven-plugin</artifactId>
    <version>1.0-alpha-3</version>
    <configuration>
        <inherited>true</inherited>
        <forkMode>once</forkMode>
        <reportFormat>xml</reportFormat>
        <classesDirectory>${project.build.directory}/generated-classes/emma/classes</classesDirectory>
        <!-- Exclusion configuration -->
        <filters>
            <filter>                                     
                <excludes>**/com.exam.generated.ceq.**</excludes>
                <excludes>**/com.exam.activities.**</excludes>
                <excludes>**/com.exam.activities.cdr.generated.**</excludes>
                <excludes>**/com.exam.admin.**</excludes>
            </filter>
         </filters>
    </configuration>
    <executions>
        <execution>
            <phase>process-classes</phase>
            <goals>
                <goal>emma</goal>
            </goals>
        </execution>
    </executions>
</plugin>