Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PowerMock ECLEmma coverage issue


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

like image 230
venkatesh Avatar asked Apr 29 '14 11:04

venkatesh


People also ask

How does EclEmma determine code coverage?

The Eclipse Plug-InEclEmma retrieves code coverage metrics as conveniently as you execute your test suites directly in the IDE . The plugin can be easily installed from its update site at http://update.eclemma.org/ on any Eclipse installation of version 3.5 or above. It is also available from the Eclipse Marketplace.

How do I get code coverage with PowerMock?

Put your powermock test logic in other simple java class inside test package, and call the merhod from test class, it increase code coverage for your application.

Does JaCoCo work with PowerMock?

JaCoCo Offline Instrumentation works only with PowerMock version 1.6. 6 and above. You may find example of using PowerMock with JaCoCo Offline Instrumentation and Maven in our repository: jacoco-offline example.


2 Answers

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

like image 88
Rodrigo Villalba Zayas Avatar answered Sep 20 '22 04:09

Rodrigo Villalba Zayas


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.

like image 31
Nyamiou The Galeanthrope Avatar answered Sep 22 '22 04:09

Nyamiou The Galeanthrope