I have Spring Boot application on which I run coverage check using jacoco-maven-plugin in version 0.7.9. The strange thing I found is that when a class is tested with more then one test class the results are not combined but I get coverage calculated using only one of the test classes.
For example: I have a Service which is covered almost 100% with ServiceTest. And then I have a Controller which depends on Service and a separate ControllerTest which by testing the Controller also touches some bits of the Service class. Now when I run all my tests with JaCoCo I get the coverage of the Service at only about 40% which means only the result of running the ControllerTest were taken into account. And the ServiceTest results were completely ignored although the tests there were executed.
So the question is whether there is something wrong here or this is simply how JaCoCo works?
So the question is whether there is something wrong here or this is simply how JaCoCo works?
Is there anything special about how JaCoCo treats abstract classes?
I managed to prepare an example of my case and pinpoint the issue.
https://github.com/juzer/spring-jacoco-demo
It seems to be related to the inheritance hierarchy and abstract classes. I have an AbstractService which is tested by instantiating an anonymous class and it's covered 100%. Then I have a concrete subclass that is also tested (only methods in this class). When I run all the tests however, the coverage of AbstractService is 0. Moving all tests to the ServiceTest results in correct coverage report - 100% on both classes.
I managed to prepare an example of my case and pinpoint the issue.
https://github.com/juzer/spring-jacoco-demo
It seems to be related to the inheritance hierarchy and abstract classes. I have an AbstractService which is tested by instantiating an anonymous class and it's covered 100%. Then I have a concrete subclass that is also tested (only methods in this class). When I run all the tests however, the coverage of AbstractService is 0. Moving all tests to the ServiceTest results in correct coverage report - 100% on both classes.I'll have a look later.
Regards,
Evgeny