I am using lombok
in my Java project annotating my object's private member variables with @Getter
and @Setter
annotations. We know that those getters and setters would work as expected. So we don't really need those to be unit tested. However, that brings down the code coverage
of the code in unit testing.
Is there a way to tell the unit testing engine that the getters and setters generated by lombok need not be tested?
If you tests use the getters/setters to achieve their goal of testing the "real" functionality, then that's good enough. If, on the other hand, your getters and setters do more than just get and set (i.e. they're properly complex methods), then yes, they should be tested.
You can always manually disable getter/setter generation for any field by using the special AccessLevel. NONE access level. This lets you override the behaviour of a @Getter , @Setter or @Data annotation on a class.
Also, I really discourage using any Lombok annotation that modifies the code. If you take @Data, @Getter, @Setter, @AllArgsConstructor adds new codes into the existing source code without modifying the code we wrote.
From Lombok 1.16.14, all generated methods will be annotated with @lombok.Generated
.
You can exclude them from the Cobertura test report:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.7</version>
<configuration>
<instrumentation>
<ignoreMethodAnnotation>lombok.Generated</ignoreMethodAnnotation>
</instrumentation>
</configuration>
</plugin>
Disclosure: I am a Lombok developer.
NB. At this time, Lombok 1.16.14 has not been released. You can download the edge release that contains this fix though.
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