Issue
I have a simple Java program which uses the Lombok Annotation - @Builder
.
I am testing my code using junit and everytime I run my unit tests, my coverage is always below 50% inspite of the fact that I am testing my entire code.
I looked into the junit generated code coverage and I saw that it was the Lombok annotation which was making the coverage drop.
I see something like:
toString() - 0%
build() - 0%
MyMethod.MyMethodBuilder() - 0%
How do I test these methods for the @Builder
annotation? Or the only way to improve coverage is to exclude those from the test coverage?
Solution
Starting JaCoCo v0.8.0, you should create lombok.config
file to the root of your project and add following content to it:
lombok.addLombokGeneratedAnnotation = true
This will add @Generated
annotation to Lombok generated files and JaCoCo will know that code coverage of such a code should be ignored.
Credits to original author here
Answered By - Ewoks
Answer Checked By - Marie Seifert (JavaFixing Admin)