How to ignore Code Coverage for Lombok generated code?

Recently I started using lombok code in one of my projects.

It reduced verbosity to a great extent .

But one issue kept popping up. The Code Coverage tool which I was using (JaCoCo) was showing zero percentage code coverage for the domain classes annotated with @Data annotation provided by lombok.

I tried writing junit test cases by manually setting values for the setter methods.

Still it didn’t improve.

And then I researched and found out a solution.

The solution is to make lombok add @lombok.Generated annotation for all the code that is generated by lombok.

That is automatically generated if we include the following property:

lombok.addLombokGeneratedAnnotation = true

This has to be placed in a file named lombok.config at the root of the project. (Example : At the same place where pom.xml is placed in case of a Maven project)

Once that is done , Lombok automatically adds the annotation @lombok.Generated at all necessary places as mentioned before. JaCoCo then ignores all the code marked with that annotation.

That’s it.

My Code Coverage got increased.

If you have more than one lombok configuration file you can add the below property in the config file:

config.stopBubbling = true

This will stop lombok from looking at any config file in parent directories.






One response to “How to ignore Code Coverage for Lombok generated code?”

  1. […] . To ignore lombok generated code while calculating code coverage follow this ( How to ignore code coverage for lombok generated code ? […]

Leave a Reply

Discover more from The Full Stack Developer

Subscribe now to keep reading and get access to the full archive.

Continue reading