简体   繁体   中英

Ignore Classes and Methods form Code Coverage (jacoco)

In my application I want to ignore to classes ( packageName1/Starter / packageName1/IO/CmdException.class) and for every class equals and hashCode method.

My pom.xml looks like:

<build>
        <plugins>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.7.0.201403182114</version>
                <configuration>
                    <instrumentation>
                        <ignores>
                            <ignore>*hashCode</ignore>
                             <ignore>*equals</ignore>
                        </ignores>
                        <excludes>
                            <exclude>packageName1/Starter.class</exclude>
                            <exclude>packageName1/IO/CmdException.class</exclude>
                        </excludes>
                    </instrumentation>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>report</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

The problem is that coverage still threats these classes and methods.

This Works for me to exclude classes.

<plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.7.8</version>

                <configuration>

                    <ignores>
                        <ignore>com.sample.package.bean.*</ignore>

                    </ignores>
                    <excludes>
                        <!-- all class which we want to exclude from the coverage report -->
                        <exclude>**/*class1.class</exclude>
                        <exclude>**/*class2.class</exclude>
                        <exclude>**/*class3.class</exclude>
                        <exclude>**/*class4.class</exclude>





                    </excludes>



                </configuration>


                <executions>
                    <execution>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>report</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM