Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ignore inner/nested classes with JaCoCo?

I'm trying to ignore some generated classes, and the classes get ignored fine. But if those classes have inner classes, those classes still get included, despite the parent class being excluded. This is my configuration:

<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>0.7.9</version>
    <executions>
        <execution>
            <goals>
                <goal>prepare-agent</goal>
            </goals>
        </execution>
        <execution>
            <id>report</id>
            <phase>prepare-package</phase>
            <goals>
                <goal>report</goal>
            </goals>
            <configuration>
                <excludes>
                    <exclude>**/*DB.*</exclude>
                    <exclude>**/*DTO.*</exclude>
                </excludes>
            </configuration>
        </execution>
    </executions>
</plugin>

Attempting to use the standard Java name convention of ParentClass.NestedClass by excluding **/*DB.*.* did not help.

like image 439
Torque Avatar asked Aug 22 '17 09:08

Torque


People also ask

How do you exclude classes in JaCoCo code coverage?

Starting from JaCoCo 0.8. 2, we can exclude classes and methods by annotating them with a custom annotation with the following properties: The name of the annotation should include Generated. The retention policy of annotation should be runtime or class.

How do you exclude classes from code coverage?

The easiest way to exclude code from code coverage analysis is to use ExcludeFromCodeCoverage attribute. This attribute tells tooling that class or some of its members are not planned to be covered with tests. EditFormModel class shown above can be left out from code coverage by simply adding the attribute.

How do I skip JaCoCo coverage?

The check goal has a skip parameter: eclemma.org/jacoco/trunk/doc/check-mojo.html#skip - so it would be -Djacoco. skip=true - it seems this skips all of the jacoco goals. If you don't want that maybe temporarily move the check goal into a profile you can activate when back on track?

How do you exclude certain classes from being included in the code coverage in Java?

Edit Configurations > Select Code Coverage tab > then adding the package or class I want to be excluded or include only in the code coverage report.


1 Answers

After some searching, I found the answer myself. As it wasn't easily googleable, I'm putting it here for posterity's sake:

The syntax mirrors that of the compiled Java naming convention:

<configuration>
    <excludes>
        <exclude>**/*DB.*</exclude>
        <exclude>**/*DB$*.*</exclude>
        <exclude>**/*DTO.*</exclude>
        <exclude>**/*DTO$*.*</exclude>
    </excludes>
</configuration>
like image 131
Torque Avatar answered Sep 20 '22 11:09

Torque