Menu

Why Jacoco report shows 0% coverage

2011-11-10
2013-04-24
  • hongjia.xuhj

    hongjia.xuhj - 2011-11-10

    HI
    I am using Jacoco for coverage in my code and my test is integrated test which mainly test interface developed by developers.
    My test tool is TestNG, I created a new testng project  which only has test cases and doesn't have any developing code. The tests can run successfuly and jacoco.exec can be generated. But report shows 0% coverage, when i click "sessions" i see all the developing class is listed, but it is just a list, not a link. So i am confused. I use maven to manage my project, its version is 2.2.1. The version of Jacoco is 0.5.3.201107060350. The POM.xml is put like this:
    <pluginManagement>
    <plugins>
    <plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>0.5.3.201107060350</version>
    </plugin>
    </plugins>
    </pluginManagement>
    <plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <configuration>
    <includes>*</includes>
    </configuration>
    <executions>
    <execution>
    <id>pre-test</id>
    <goals>
    <goal>prepare-agent</goal>
    </goals>
    </execution>
    <execution>
    <id>jacoco-report</id>
    <phase>test</phase>
    <goals>
    <goal>report</goal>
    </goals>
    </execution>
    </executions>
    </plugin>

     
  • Marc R. Hoffmann

    So, do you see the packages and classes under test listed in the hierarchical report?

    If yes, do you use any other tool in your test, that modifies the class files (AspectJ, some mocking framework, any other Java agent)? JaCoCo is very sensitive about changes between the executed class files and the one seen at reporting time.

     
  • hongjia.xuhj

    hongjia.xuhj - 2011-11-11

    Thanks, I see lists in "sessions" and it has some word like "..EnhancerByCGLIB..f318fb85" or "..b6323a87" behind name of many lists, Does this mean the class has been modified?

     
  • Marc R. Hoffmann

    It definitely looks like CGLIB is modifying classes here. That won't work with JaCoCo.

     
  • Tamas Kende

    Tamas Kende - 2012-02-09

    Hi,

    I have the same problem, but in the session page I see no sign of any class modification. How can I find out what is the problem? I use the jacoco agent on a separate machine, and with another project it works well.. I use includes but it has no effect if I change it to excludes (I have to use it because I have problems with drools. It cause some troubles during instrumentation)

    any idea how can I find out what is happening?

     
  • Marc R. Hoffmann

    Make sure that the classes you use at runtime are exactly the same class files you use for time. Also make sure that no other tool modifies the classes loaded into the JVM.

    Cheers,
    -marc

     
  • Tamas Kende

    Tamas Kende - 2012-02-10

    The class files are the same… I will try to find out is there any modifier staff in the JVM…. so this case could happen only if the class files used for reporting are not the same that was in the JVM?

     
  • Marc R. Hoffmann

    JaCoCo uses a hashcode of the class definition for class identity. If a class is not reported as covered but a class with the same name is listed on the session page it clearly indicates that the class seen by the JaCoCo agent was a different one from the one used for report generation.

     
  • zalavaari

    zalavaari - 2012-05-10

    Is there any hope for Jacoco will handle cglib modified classes in the near future?
    So will it possible in the future to use it for coverage PowerMock and JMockit tests?
    (1.5.3 and older eclemma versions are okay, so we still use it for these tests…)

    Thanks for your answer in advance!

     
  • Marc R. Hoffmann

    Hi,

    to be honest I don't see a chance to work on this in the near future.

    Cheers,
    -marc