Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lombok annotations vs code coverage in Cobertura or similar tool

Configure cobertura to ignore certain blocks of code

From what I have read from above question, there's no way in Cobertura to exclude given code part from being tested versus having coverage in tests.

Is that true? / Is it possible in any simmilar tool?

I'm usuing Lombok annotations @Getter, @Setter and so on, which are great, but they result in being 'red' in coverage report, even if I'm testing getter and setter methods. - I would like to do something with that... Is there any way to fix this?

like image 919
dantuch Avatar asked Apr 23 '12 07:04

dantuch


2 Answers

Isn't it possible to first run delombok over the code under test, compile it and then instrument it by Cobertura?

Disclosure: I am one of the Project Lombok developers

like image 176
Roel Spilker Avatar answered Nov 09 '22 15:11

Roel Spilker


Lombok adds a @javax.annotation.Generated annotation (1). But this annotation has source retention, i.e. your coverage tool can't see it any more :-(

Lombok 1.16.14 just fixed issue-1014 by adding an option to generate a @lombok.Generated annotation instead; just configure lombok.addLombokGeneratedAnnotation(2).

Cobertura can be configured to skip methods with some annotation, so most of the generated code won't count against your coverage.

JaCoCo doesn't provide a configuration mechanism to skip on certain annotations. Issue-15 tries to fix this (and much more) without requiring any configuration.

(1) If not disabled with lombok.addGeneratedAnnotation which is now deprecated and should be replaced with lombok.addJavaxGeneratedAnnotation
(2) see lombok config
(3) see this comment

like image 33
rü- Avatar answered Nov 09 '22 13:11

rü-