Hi,

Mockito.spy() modifies the class under test. So JaCoCo sees a different class 
at runtime than when creating the report. This is not supported by JaCoCo. See 
FAQ <https://www.jacoco.org/jacoco/trunk/doc/faq.html>:
> Why does a class show as not covered although it has been executed?
> 
> First make sure execution data has been collected. For this select the 
> Sessions link on the top right corner of the HTML report and check whether 
> the class in question is listed. If it is listed but not linked the class at 
> execution time is a different class file. Make sure you're using the exact 
> same class file at runtime as for report generation. Note that some tools 
> (e.g. EJB containers, mocking frameworks) might modify your class files at 
> runtime. Please see the chapter about class ids 
> <https://www.jacoco.org/jacoco/trunk/doc/classids.html> for a detailed 
> discussion. 
> 


Best regards,
-marc


> On 10. May 2022, at 23:33, Shashank Chaudhry <schaud...@spotnana.com> wrote:
> 
> My company is using the jacoco-maven-plugin 0.8.5 and I seem to be observing 
> some odd behavior. I'll briefly try to explain what we're doing, but please 
> feel free to ask me more questions.
> 
> There is an abstract class (BaseClient) I want to test, which has some 
> non-abstract functions.
> 
> abstract class BaseClient {
>   protected void someFn() {
>     log.error("This ran");
>     .....stuff.....
>   }
> }
> 
> To test it, we extend it (TestClient).
> 
> class TestClient extends BaseClient {
>   @Override
>   public void someFn() {
>     return super.someFn();
>   }
> }
> 
> The TestClient is created in test files with Mockito.spy().
> 
> When I run the tests, I see that the BaseClient function actually ran, 
> because logs that I added get printed. I also see that using the inbuilt 
> IntelliJ coverage tool, I get coverage for the function in the abstract 
> class. But I Jacoco, the entire BaseClient has 0% coverage.
> 
> Thanks,
> Shashank
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "JaCoCo and EclEmma Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to jacoco+unsubscr...@googlegroups.com 
> <mailto:jacoco+unsubscr...@googlegroups.com>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/jacoco/15592d8d-aff9-48c4-af1b-4b1f2f74dba8n%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/jacoco/15592d8d-aff9-48c4-af1b-4b1f2f74dba8n%40googlegroups.com?utm_medium=email&utm_source=footer>.

-- 
You received this message because you are subscribed to the Google Groups 
"JaCoCo and EclEmma Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jacoco+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jacoco/39630DE6-BDBC-46C8-A92F-2C7FBF12E016%40mountainminds.com.

Reply via email to