PowerMock ECLEmma coverage issue

venkatesh picture venkatesh · Apr 29, 2014 · Viewed 29.1k times · Source


We are using EasyMock and PowerMock with JUnit. The coverage tool used is ECLEmma. With EasyMock, it shows the coverage properly in green (as covered). However, for the code that is unit tested with PowerMock, the coverage is shown in red (uncovered). Have read similar questions on the web. However, just wanted to check if there is a solution for this.

Thanks
Venkatesh

Answer

Rodrigo Villalba Zayas picture Rodrigo Villalba Zayas · Feb 24, 2016

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