I am writing unit tests for my project and am trying to achieve at least 80% code coverage. Problem is that I am using lombok's @Data
annotation for generating getters and setters and when I run my unit tests, all those getters and setters along with other methods like toString
, equals
, hashcode
etc are missed and my code coverage takes a hit. Is there any workaround for this. I have been searching a lot about this but haven't been able to find anything which could help out. Any help on this would be appreciated.
I am using Eclemma for code coverage analysis.
In 0.8.0 release, Jacoco added support for filtering out all methods annotated with @lombok.Generated
from their reports. The only thing you need to change is to add lombok.config
to the root of your project with the following settings:
config.stopBubbling = true
lombok.addLombokGeneratedAnnotation = true
config.stopBubbling = true
tells Lombok that this is your root
directory and that it should not search parent directories for more
configuration files (you can have more than one lombok config files
in different directories/packages).lombok.addLombokGeneratedAnnotation = true
will add @lombok.Generated
annotation to all Lombok generated methods.And that's it. Jacoco will filter Lombok auto-generated methods, and if you give your best, your code coverage could be close to 100% :))