tiebin-zhang / powermock

Automatically exported from code.google.com/p/powermock
Apache License 2.0
0 stars 0 forks source link

PowerMock disables EclEmma code coverage #402

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.Create a powermock test with Mockito, the test class is decorated with 
@RunWith and @PrepareForTest annotation.
2.Run the Test with "coverage as".

What is the expected output? What do you see instead?
Expected: EclEmma shows correct code coverage report.
Instead: EclEmma shows zero code coverage on target class.

What version of the product are you using? On what operating system?
 1. Eclipse is 3.7. 
 2. EclEmma Plugin: 2.1.4. 
 3. PowerMock: powermock-mockito-1.4.12-full.jar.
 4. OS: Windows XP sp2. 
 5. JDK: 1.6.

Please provide any additional information below.
N/A.

Original issue reported on code.google.com by linmingr...@gmail.com on 10 Sep 2012 at 7:55

GoogleCodeExporter commented 9 years ago
Could someone try if you get the same result if you test with the very latest 
(unreleased) Javassist?

Original comment by johan.ha...@gmail.com on 12 Oct 2012 at 10:58

GoogleCodeExporter commented 9 years ago
We are using latest unreleased Javassist and can confirm that the coverage 
report shows zero code coverage when using powermock tests with Mockito as 
reported in the original post.

Original comment by mahnk...@gmail.com on 16 Oct 2012 at 10:52

GoogleCodeExporter commented 9 years ago
I have the same issue:

EclEmma 2.1.4.201208011137
Eclipse 4.2
OpenJDK 7
ArchLinux 3.6.2-1 i686
powermock-api-mockito 1.4.12

Original comment by ccha...@gmail.com on 16 Oct 2012 at 8:05

GoogleCodeExporter commented 9 years ago
Did this occur with a new version of EclEmma or how come it has not been 
reported before?

Original comment by johan.ha...@gmail.com on 17 Oct 2012 at 6:01

GoogleCodeExporter commented 9 years ago
In our case we started to use powermock in order to be able to mock static 
methods and since then code coverage reports are incorrectly showing zero code 
coverage for the class we are testing using powermock.

Original comment by mahnk...@gmail.com on 17 Oct 2012 at 7:06

GoogleCodeExporter commented 9 years ago
Alright. I know cobertura had the same issue before but then it was an issue on 
their side this they fixed it a later version. Perhaps you can bring this up to 
Emma as well?

Original comment by johan.ha...@gmail.com on 17 Oct 2012 at 7:13

GoogleCodeExporter commented 9 years ago
https://github.com/jacoco/eclemma/issues/15

Original comment by gabor.li...@gmail.com on 17 Oct 2012 at 7:17

GoogleCodeExporter commented 9 years ago
If someone would have time to provide a test and a dummy class attached to this 
class, that would be useful for both parties.

Original comment by gabor.li...@gmail.com on 17 Oct 2012 at 7:18

GoogleCodeExporter commented 9 years ago
Please find attached a sample dummy project demonstrating the reported issue.

When running code coverage for unit test 
"TestClassUsingMockedStaticMethod.java", it shows zero % coverage in 
src/main/java

When running code coverage for unit test "TestClassUsingRealStaticMethod.java", 
it shows correct coverage % in src/main/java

Original comment by mahnk...@gmail.com on 17 Oct 2012 at 9:27

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks for the sample classes.

Original comment by gabor.li...@gmail.com on 17 Oct 2012 at 9:32

GoogleCodeExporter commented 9 years ago
This problem began with EclEmma 2.0.0, where they started using Jacoco.
With EclEmma 1.5.3 there is no such problem.

Original comment by zalava...@gmail.com on 17 Oct 2012 at 8:59

GoogleCodeExporter commented 9 years ago
Then I suspect that problem must be fixed in Jacoco or Emma?

Original comment by johan.ha...@gmail.com on 18 Oct 2012 at 4:41

GoogleCodeExporter commented 9 years ago
Yes, maybe. But they won't fix it:
http://sourceforge.net/projects/eclemma/forums/forum/614869/topic/4803215

Original comment by zalava...@gmail.com on 18 Oct 2012 at 5:46

GoogleCodeExporter commented 9 years ago
Ok so there it says that "JaCoCo uses a hashcode of the class definition for 
class identity" so that's probably the reason why it won't work. PowerMock 
cannot work with modifying classes so I guess there's nothing that can be done 
in PowerMock to prevent this.. (correct me if I'm wrong).

Original comment by johan.ha...@gmail.com on 18 Oct 2012 at 5:52

GoogleCodeExporter commented 9 years ago
The root of the problem: "JaCoCo uses a hashcode of the class definition for 
class identity."
So the cglib modified classes has different hashcodes than the originals.
I don't think the PowerMock guys can solve this problem, so I think this will 
be a long-term problem.

Original comment by zalava...@gmail.com on 18 Oct 2012 at 5:55

GoogleCodeExporter commented 9 years ago
:)

Original comment by zalava...@gmail.com on 18 Oct 2012 at 5:56

GoogleCodeExporter commented 9 years ago
I have just installed ecobertura. Works perfectly together with eclemma inside 
one eclipse. It is less handy as eclemma, but it delivers correct coverage. If 
you drag this link on eclipse, you can install that easily: 
http://marketplace.eclipse.org/marketplace-client-intro?mpc_install=1179

Original comment by gabor.li...@gmail.com on 18 Oct 2012 at 1:01

GoogleCodeExporter commented 9 years ago
Yes, Cobertura is okay but it is not maintained anymore. (It hasn't got any 
update since 2011 june, so this is not a long term solution I think)

At the company we using Sonar, it has Cobertura and Jacoco plugins as well, but 
the supported way in sonar is also Jacoco for sime time.

Original comment by zalava...@gmail.com on 19 Nov 2012 at 9:37

GoogleCodeExporter commented 9 years ago
Seems to be related to #432.

Original comment by headcrashing on 22 Feb 2013 at 6:45

GoogleCodeExporter commented 9 years ago
There forecasting correction?

Original comment by giovanim...@gmail.com on 10 Apr 2013 at 2:35

GoogleCodeExporter commented 9 years ago
We use EasyMock with PowerMock and got similar issue. The only difference is 
that we always got 100% coverage of the under test class, even though there are 
lines not covered.

Original comment by eric...@gmail.com on 14 Apr 2013 at 11:25

GoogleCodeExporter commented 9 years ago
I just tried using Clover with Powermock and it works. Not free but at least it 
works. 

Original comment by hghazo...@gmail.com on 26 Jun 2013 at 10:21

GoogleCodeExporter commented 9 years ago
Facing the same issue. EclEmma giving zero code coverage with powermock based 
unit test.

Original comment by dakbhav...@gmail.com on 25 May 2015 at 1:18