5

We are using Jacoco and eclemma for test case coverage. For the classes that are not using PowerMockRunner we are getting coverage properly in both.For the classes that uses PowerMockRunner we are facing issue with coverage like it shows 0 % coverage in jacoco but shows proper coverage in eclemma.

PowerMockito version :1.7.1
Jdk 1.8
Jacoco:0.7.9

I tried to use PowerMockRunner rule also but this causes another error related to verify stackframe which is very difficult to fix. Eclemma is used as eclipse plugin and jacoco is used as maven plugin. Any one who has faced this issue and are able to fix this can shed some light on this.I have gone through many links but none of them worked out for me.

Some useful reference:

PowerMock ECLEmma coverage issue

Stefan Birkner
  • 24,059
  • 12
  • 57
  • 72
Pradeep
  • 1,947
  • 3
  • 22
  • 45

3 Answers3

4

PowerMock does not work with Jacoco

Jira for the bug

Jacoco and powermock don't work well , so in order to get coverage we can use offline version of jacoco.

I had put together an example

https://github.com/muhdkhokhar/powermock-jacoco-coverage

Makky
  • 17,117
  • 17
  • 63
  • 86
  • For some powemockito classes it shows % in jacoco .Then how come we can generalize "It won't work" ?.Don't mind . – Pradeep Oct 16 '17 at 13:00
0

offline insturmentation of jacoco and powermock is working perfectly and on-the-fly instrumentation is not working and powermock team is working on this. Refer the below mentioned URL'S.

https://github.com/powermock/powermock/issues/727

https://github.com/powermock/powermock/wiki/Code-coverage-with-JaCoCo

-1

PowerMock can work with JaCoCo

My configuration is:

<powermock-version>2.0.9</powermock-version>
<jacoco.version>0.8.1</jacoco.version>
    
<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>${jacoco.version}</version>
    <configuration>
        <excludes>
            <exclude>...</exclude>
        </excludes>
    </configuration>
    <executions>
        <execution>
            <id>prepare-agent</id>
            <goals>
                <goal>prepare-agent</goal>
            </goals>
        </execution>
        <execution>
            <id>report</id>
            <phase>prepare-package</phase>
            <goals>
                <goal>report</goal>
            </goals>
        </execution>
    </executions>
</plugin>

notice:【important!!!!】 You can't use include. if you use include, the coverage is always zero. but you can use exclude.

Saeid Amini
  • 1,313
  • 5
  • 16
  • 26
ccqccq
  • 1