Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclemma always reporting 0% of code coverage

Tags:

java

eclemma

I have a Maven test project for my application.

The JUnit tests run fine, and the code coverage test run too.

But the report always shows 0% of code coverage.

What should i do?

like image 669
renanleandrof Avatar asked Dec 18 '12 11:12

renanleandrof


2 Answers

If you are using eclemma, you need to add jacoco dependency. if jacoco has been added and still, you are facing this issue, refer the eclemma faq: "Why does a class show as not covered although it has been executed?"

it says,

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.

So, Mockito / PowerMockito can cause this problem. In my case, I have added the class in @PrepareForTest(). I was shown that the test case was executed fine without errors but Jacoco did't improve the code coverage in its report.

Finally, removing the class from @PrepareForTest() annotation improved the code coverge. check if you have added it or not and remove it from annotation if added.

like image 115
swaroop Avatar answered Sep 25 '22 09:09

swaroop


According to the official site, Eclemma is a code coverage plugin for Eclipse, based on JaCoCo library.

As you want to use the same code coverage engine outside eclipse, you should include the plugin Jacoco inside the Maven configuration (pom) of your project, as the following (this code was copied from the Agile Engineering blog):

<build>
    <plugins>
        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.6.0.201210061924</version>
            <executions>
                <execution>
                    <id>jacoco-initialize</id>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                </execution>
                <execution>
                    <id>jacoco-site</id>
                    <phase>test</phase>
                    <goals>
                        <goal>report</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

To run the tests just type the following on the command line tool:

mvn clean test

p.s.: you also could use other code coverage plugins like Cobertura or Emma.

like image 26
Joao Piccinini Avatar answered Sep 21 '22 09:09

Joao Piccinini