This repository has been archived by the owner. It is now read-only.

PowerMock disables EclEmma code coverage #15

Closed
liptga opened this Issue Oct 17, 2012 · 11 comments

Comments

Projects
None yet
6 participants
@liptga

liptga commented Oct 17, 2012

Original report can be seen here: http://code.google.com/p/powermock/issues/detail?id=402

Powermock guys asked us to report here as well.

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.

@marchof

This comment has been minimized.

Show comment Hide comment
@marchof

marchof Oct 17, 2012

Owner

JaCoCo doesn't play well with dynamically modified/created classes (this is the way how powermock works). This is a known limitation we can't currently do anything about.

Owner

marchof commented Oct 17, 2012

JaCoCo doesn't play well with dynamically modified/created classes (this is the way how powermock works). This is a known limitation we can't currently do anything about.

@marchof marchof closed this Oct 17, 2012

@Godin

This comment has been minimized.

Show comment Hide comment
@Godin

Godin Oct 18, 2012

Member

@marchof what about offline instrumentation? Anyway we need it for support of projects for Android.

Member

Godin commented Oct 18, 2012

@marchof what about offline instrumentation? Anyway we need it for support of projects for Android.

@liptga

This comment has been minimized.

Show comment Hide comment
@liptga

liptga Oct 18, 2012

Yeah. It would be also ok for me, if the eclemma could modify the compilation in eclipse to get instrumented class files. With such classes I guess there would be no problem together with Powermock or Mockito.

liptga commented Oct 18, 2012

Yeah. It would be also ok for me, if the eclemma could modify the compilation in eclipse to get instrumented class files. With such classes I guess there would be no problem together with Powermock or Mockito.

@Godin

This comment has been minimized.

Show comment Hide comment
@Godin

Godin Oct 18, 2012

Member

oh, I mostly talked about environments like Maven, not sure that offline instrumentation is a good choice within Eclipse

Member

Godin commented Oct 18, 2012

oh, I mostly talked about environments like Maven, not sure that offline instrumentation is a good choice within Eclipse

@marchof

This comment has been minimized.

Show comment Hide comment
@marchof

marchof Oct 18, 2012

Owner

I wouldn't go for offline instrumentation in Eclipse any more. Offline instrumentation means to either

a) replace existing class files (which requires a manual rebuild afterwards) and/or
b) poke around with (boot) class paths in framework specific ways.

Both caused a lot of trouble with EclEmma 1.x and I'm not willing to take this maintenance nightmare again.

Offline instrumentation as an Ant and Maven feature is ok for me, as long as it is up to the users to set up their environments properly (inject instrumented classes, add JaCoCo runtime in a way that it is accessible from all classes).

Owner

marchof commented Oct 18, 2012

I wouldn't go for offline instrumentation in Eclipse any more. Offline instrumentation means to either

a) replace existing class files (which requires a manual rebuild afterwards) and/or
b) poke around with (boot) class paths in framework specific ways.

Both caused a lot of trouble with EclEmma 1.x and I'm not willing to take this maintenance nightmare again.

Offline instrumentation as an Ant and Maven feature is ok for me, as long as it is up to the users to set up their environments properly (inject instrumented classes, add JaCoCo runtime in a way that it is accessible from all classes).

@Godin

This comment has been minimized.

Show comment Hide comment
@Godin

Godin Oct 18, 2012

Member

@marchof That's exactly what I had in mind.

Member

Godin commented Oct 18, 2012

@marchof That's exactly what I had in mind.

@liptga

This comment has been minimized.

Show comment Hide comment
@liptga

liptga Oct 18, 2012

Ecobertura can be a good alternative (slower, but works correctly in this cases).

Ecobertura documentation:

How does it work?

Upon launching in covered mode, eCobertura will apply any filters defined in the launch configuration. Then it will copy all classes from the output folder into its internal plugin workspace. There, it will instrument any classes that pass the filtering using Cobertura.

Within the launch configuration classpath, the output folder will be replaced by the internal plugin workspace, so that the launch uses the instrumented classes instead of the original ones.

In short, eCobertura does not do in-place instrumentation.

Cobertura will save a "cobertura.ser" file when the launched process terminates. This file will be interpreted by eCobertura and displayed in the Coverage Session View.

liptga commented Oct 18, 2012

Ecobertura can be a good alternative (slower, but works correctly in this cases).

Ecobertura documentation:

How does it work?

Upon launching in covered mode, eCobertura will apply any filters defined in the launch configuration. Then it will copy all classes from the output folder into its internal plugin workspace. There, it will instrument any classes that pass the filtering using Cobertura.

Within the launch configuration classpath, the output folder will be replaced by the internal plugin workspace, so that the launch uses the instrumented classes instead of the original ones.

In short, eCobertura does not do in-place instrumentation.

Cobertura will save a "cobertura.ser" file when the launched process terminates. This file will be interpreted by eCobertura and displayed in the Coverage Session View.

@marchof

This comment has been minimized.

Show comment Hide comment
@marchof

marchof Oct 18, 2012

Owner

I know, eCobertura architecture is a 1:1 copy of EclEmma 1.x ;-)

I don't now why but eCobertura is not maintained any more since two years. I want to keep things simple and alive here.

Owner

marchof commented Oct 18, 2012

I know, eCobertura architecture is a 1:1 copy of EclEmma 1.x ;-)

I don't now why but eCobertura is not maintained any more since two years. I want to keep things simple and alive here.

@Gael Gael referenced this issue in gwt-test-utils/gwt-test-utils May 22, 2013

Open

Emma code coverage isn't working in 0.42 version #18

@88chico

This comment has been minimized.

Show comment Hide comment
@88chico

88chico Jan 12, 2014

Guys,

I made it work using the javaagent of PowerMock.
see here: https://code.google.com/p/powermock/wiki/PowerMockAgent
i know it is experimental, but worked for me.
i am using maven.
so remove the @RunWith annotations, put the PowerMockRule as described in the link above.
Put the following line in the maven-surefire-plugin configuration:
-javaagent:${org.powermock:powermock-module-javaagent:jar}
(used the technique described here : http://stackoverflow.com/questions/2359872/can-i-use-the-path-to-a-maven-dependency-as-a-property/6934552#6934552)

with jacoco - it worked like a charm for me..

hope it`s help anyone out there..
Adi

88chico commented Jan 12, 2014

Guys,

I made it work using the javaagent of PowerMock.
see here: https://code.google.com/p/powermock/wiki/PowerMockAgent
i know it is experimental, but worked for me.
i am using maven.
so remove the @RunWith annotations, put the PowerMockRule as described in the link above.
Put the following line in the maven-surefire-plugin configuration:
-javaagent:${org.powermock:powermock-module-javaagent:jar}
(used the technique described here : http://stackoverflow.com/questions/2359872/can-i-use-the-path-to-a-maven-dependency-as-a-property/6934552#6934552)

with jacoco - it worked like a charm for me..

hope it`s help anyone out there..
Adi

@ashwin-krishnamurthy

This comment has been minimized.

Show comment Hide comment
@ashwin-krishnamurthy

ashwin-krishnamurthy Oct 7, 2015

I know its pretty late but, this pretty much did the trick. I used sonar for analysis.

I know its pretty late but, this pretty much did the trick. I used sonar for analysis.

@ProTrent

This comment has been minimized.

Show comment Hide comment

@Godin Godin locked and limited conversation to collaborators Jan 11, 2017

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.