According to this Lombok documentation , there are 7 things generated by annotating a class with @Builder , one of them being " A sensible toString() implementation "
In the project I am working on, this default toString() method has in fact caused some annoyance that jacoco report considers the method was not tested, and indeed it wasn't, because I did not mean to have a toString() method at all.
Is there a way to avoid the generation of the default toString() method, and if so, how?
Any thoughts or insight would be much appreciated.
I don't think you can remove toString(), but you can always just test it and validate that there is no nullPointerException throne.
If you have np methods in your class, then it would be better just add this class as an exception and logbook is tested by default and there is no specific logic from your code.
Unfortunately there is no way to exclude toString()
from generated builders.
But you can configure your lombok to generate code which will be ignored by JaCoCo. It is useful to exclude from test code coverage not only toString()
methods but also all getters, setters, builders, and other staff generated by lombok.
lombok.config
file into your root project dir config.stopBubbling = true
lombok.addLombokGeneratedAnnotation = true
More details about configuring lombok you can find here: https://projectlombok.org/features/configuration
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.