PowerMock ECLEmma coverage issue

Yes, there is a solution for this:

First you will have to add this maven dependency:

<dependency>
  <groupId>org.powermock</groupId>
  <artifactId>powermock-module-junit4-rule-agent</artifactId>
  <version>1.6.4</version>
  <scope>test</scope>
</dependency>

Then, instead of using this annotation @RunWith(PowerMockRunner.class), just add a @Rule in the Test class like this:

public class Test {

   @Rule
   public PowerMockRule rule = new PowerMockRule();

you can find more in this blog Make EclEmma test coverage work with PowerMock


It's a known problem : https://github.com/jayway/powermock/issues/422

And it has been for a long time, it won't be fixed anytime soon.

I suggest you use eCobertura instead.


This has worked in most cases in my project:

@Rule
public PowerMockRule rule = new PowerMockRule();
static {
    PowerMockAgent.initializeIfNeeded();
}

Remove/Comment @RunWith(PowerMockRunner.class) & include following imports after adding powermock-module-javaagent-1.6.5.jar in your classpath:

import org.junit.Rule;
import org.powermock.modules.junit4.rule.PowerMockRule;
import org.powermock.modules.agent.PowerMockAgent;

Now right click->Coverage As->Coverage Configurations and add following lines in Arguments:

-ea -noverify -javaagent:path/to/powermock-module-javaagent-1.6.5.jar

Click Apply->Coverage.

Also note that @Before would not work in this case so you have to add all the stuffs in the methods marked with @Test from the method marked with @Before.