Lombok annotations vs code coverage in Cobertura or similar tool

喜夏-厌秋 提交于 2019-12-08 14:58:21

问题


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?


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/10276666/lombok-annotations-vs-code-coverage-in-cobertura-or-similar-tool

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!