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.
Use Automation Tools and Frameworks Software test automation is no longer a hidden method for achieving faster coverage. Test automation frameworks such as Selenium, Appium, Cypress, etc. enable teams to run parallel tests for web and mobile apps faster.
@Value is the immutable variant of @Data ; all fields are made private and final by default, and setters are not generated. The class itself is also made final by default, because immutability is not something that can be forced onto a subclass.
@Data is a convenient shortcut annotation that bundles the features of @ToString , @EqualsAndHashCode , @Getter / @Setter and @RequiredArgsConstructor together: In other words, @Data generates all the boilerplate that is normally associated with simple POJOs (Plain Old Java Objects) and beans: getters for all fields, ...
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% :))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With