Exclusion of method (main)

42 views
Skip to first unread message

Brandon Largeau

unread,
Oct 14, 2020, 3:36:06 AM10/14/20
to JaCoCo and EclEmma Users
Hello,

I searched a lot about this but nothing really work.

I'd like to exclude "main(String[] args)" from the coverage because this isn't really a functionnality to test.

I'm using jacoco through Gradle.

Why do I want that ? Because main isn't covered by the tests (since there's nothing to test in it).

Should I put a call to main in the JUnit test ?

I tested @Generated or even @ExcludeFromCodeCoverage but doesn't work.

Thanks you!

Marc Hoffmann

unread,
Oct 14, 2020, 3:47:11 AM10/14/20
to jac...@googlegroups.com
Hi,

the @Generated annotation needs to be of retention CLASS or RUNTIME.

 Hint: javax.annotation.Generated which ships with the JDK has retention SOURCE and does not work for JaCoCo.

Regards,
-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/efba312b-275b-47cf-bd90-a3b6c7e57b00n%40googlegroups.com.

Evgeny Mandrikov

unread,
Oct 14, 2020, 4:47:28 AM10/14/20
to jac...@googlegroups.com
On Wed, Oct 14, 2020 at 9:47 AM Marc Hoffmann <hoff...@mountainminds.com> wrote:
the @Generated annotation needs to be of retention CLASS or RUNTIME.

 Hint: javax.annotation.Generated which ships with the JDK has retention SOURCE and does not work for JaCoCo.

In an addition to what was already written by Mark:
Please also note that we do not recommend to use annotations for manual tagging - they are not designed for this,
A Generated annotation should only be used for code actually generated by compilers or tools, never for manual exclusion.

On 14. Oct 2020, at 09:36, Brandon Largeau <brandon...@gmail.com> wrote:
Should I put a call to main in the JUnit test ?

Yes, you can do this.

Or your main method can be the only method of a class and so you can exclude the whole class.

Or you can simply ignore the fact that the main method shows as uncovered.

Brandon Largeau

unread,
Oct 14, 2020, 3:51:48 PM10/14/20
to JaCoCo and EclEmma Users
Hello,

Thanks for the answers !

So I think there's no way to exclude a method fromt the coverage using Jacoco I think.

I'll put the main method alone and exclude it then, thanks for the idea.

Any tuto on how to achieve that using Gradle ? I already tested some idea from the internet but nothing actually work.

Thank you for your help.

Evgeny Mandrikov

unread,
Oct 15, 2020, 5:35:28 AM10/15/20
to JaCoCo and EclEmma Users
On Wednesday, October 14, 2020 at 9:51:48 PM UTC+2 Brandon Largeau wrote:
Hello,

Thanks for the answers !

So I think there's no way to exclude a method fromt the coverage using Jacoco I think.

I'll put the main method alone and exclude it then, thanks for the idea.

Any tuto on how to achieve that using Gradle ? I already tested some idea from the internet but nothing actually work.

Reply all
Reply to author
Forward
0 new messages