You can use MockitoJunitRunner and specify a rule to use PowerMock since Eclemma works along with MockitoJUnitRunner.
Something like this:
@RunWith(MockitoJUnitRunner.class) // This supports Eclemma Plugin. Powermock doesn't.
@PrepareForTest({/* StaticClasses for Powermock here */})
public class ClassTest {
// These two statements; the static block and @Rule make sure Powermock works along with Mockito!!
static {
PowerMockAgent.initializeIfNeeded();
}
@Rule
public PowerMockRule powerMockRule = new PowerMockRule();
@Mock // To mock dependent class
private MockClass mock;
@InjectMocks //To Inject all mocks in this class
private ClassUnderTest classObject;
//Rest of the code here.
}
Dependencies needed:
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>1.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4-rule-agent</artifactId>
<version>1.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
<scope>test</scope>
</dependency
Also you need to add this to the configurations under Coverage As -> Coverage Configurations -> Arguments.
Inside VM Arguments add -noverify and save.
for this to work with Jacoco use the following statement in your pom.xml .
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<argLine>${argLine} -noverify -javaagent:${settings.localRepository}/org/powermock/powermock-module-javaagent/1.6.2/powermock-module-javaagent-1.6.2.jar</argLine>
</configuration>
</plugin>