Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How do you get coverage for source code generated by an annotation processor?

Mark Malynn
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 21, 2018

I've developed a java annotation processor (here is a good tutorial). I would like to get code coverage of the generated source code and have had no luck. I use maven as the build tool. Note that the class names of the generated source files contain '$$' to minimize the chance of class name collision (e.g., my/package/Foo$$Bar.java). The root of the source tree is target/generated-test-sources/test-annotations (maven's standard location for sources generated during a test compile).

How do I configure the clover maven plugin such that clover2:setup instruments these generated sources?

 

1 answer

0 votes
Grzegorz Lewandowski
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 23, 2018

When using Clover with any code source generation user must ensure code generation happens before Clover instrumentation happens.

With code annotation processors this is a tricky part because those are processed in-the-fly by Java compiler.

What you may want to experiment with is to process the annotations via some plugin, make sure it's invoked before Clover.

 

Out of curiosity, why do you want to track coverage for a generated code? Usually it's a boilerplate code without any valid business logic in it.

Mark Malynn
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 23, 2018

Thanks for the explanation and suggestion.

You're correct that it basically generates boilerplate code, but different annotation combinations interact with each other. I have tests that verify the interaction... since I have tests, I want code coverage.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events