Getting 0% coverage for abstract class

1,129 views
Skip to first unread message

Shashank Chaudhry

unread,
May 10, 2022, 5:33:21 PM5/10/22
to JaCoCo and EclEmma Users
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

Marc Hoffmann

unread,
May 16, 2022, 3:26:42 AM5/16/22
to JaCoCo and EclEmma Users
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:

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 for a detailed discussion. 


Best regards,
-marc


--
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+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jacoco/15592d8d-aff9-48c4-af1b-4b1f2f74dba8n%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages