How can we exclude method from JaCoCo Code coverate

9,753 views
Skip to first unread message

Irene Chai

unread,
Mar 15, 2021, 7:55:45 PM3/15/21
to JaCoCo and EclEmma Users

Hi,


Looks like
@ExcludeFromCodeCoverage is supported on JacCoCo 0.8.2+

But when we add it, we got build failures.

Is any other annotation supported to exclude a method/function from code coverage report in Java ?

Thanks
IR

Marc Hoffmann

unread,
Mar 16, 2021, 4:47:34 AM3/16/21
to JaCoCo and EclEmma Users
Can you please post the full error message of the build failure?

Thx,
-marc


--
You received this message because you are subscribed to the Google Groups "JaCoCo and EclEmma Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jacoco+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jacoco/679458bc-0854-4e75-855c-eac9c1b9276an%40googlegroups.com.

Irene Chai

unread,
Mar 16, 2021, 1:34:57 PM3/16/21
to jac...@googlegroups.com
Source code is

  @ExcludeFromCodeCoverage
    public void testABC(){
        int a =1;
        int b = 1;
        System.out.println("a=" + a);
    }

Maven is :

            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.6</version>
                <executions>
                    <execution>
                        <id>pre-unit-test</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                        <configuration>
                            <destFile>${sonar.jacoco.reportPath}</destFile>
                            <append>true</append>
                        </configuration>
                    </execution>
                </executions>
            </plugin>


Build Failure is :

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project pushservice-rest: Compilation failure
[ERROR]  /PushData.java:[812,6] cannot find symbol
[ERROR]   symbol:   class ExcludeFromCodeCoverage
[ERROR]   location: class xxx.PushData
[ERROR]

Thanks,
IR

You received this message because you are subscribed to a topic in the Google Groups "JaCoCo and EclEmma Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jacoco/FOWhUb-Xj3g/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jacoco+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jacoco/9139F51D-DBCB-4DEE-8CD1-01DDCC819D47%40mountainminds.com.

Marc Hoffmann

unread,
Mar 16, 2021, 2:20:30 PM3/16/21
to JaCoCo and EclEmma Users
Well you actually need to declare that annotation in your code base. For example:


@Retention(RetentionPolicy.CLASS)
public @interface ExcludeFromCodeCoverage {
}



Irene Chai

unread,
Mar 16, 2021, 2:48:56 PM3/16/21
to JaCoCo and EclEmma Users
Thanks Marc !

Does  JaCoCo report will skip the method from code coverage if this annotation "ExcludeFromCodeCoverage"  ?

Irene Chai

unread,
Mar 16, 2021, 2:49:55 PM3/16/21
to JaCoCo and EclEmma Users
What we want is to achieve is to skip some methods from code coverage reports.

Thanks
IR

Marc Hoffmann

unread,
Mar 16, 2021, 3:05:05 PM3/16/21
to jac...@googlegroups.com
Does  JaCoCo report will skip the method from code coverage if this annotation "ExcludeFromCodeCoverage"  ?

Actually not. My bad. Only annotations that contain the string “Generated” will make the methods disappear from the coverage report.


Irene Chai

unread,
Mar 16, 2021, 5:01:09 PM3/16/21
to jac...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages