PowerMock disables code coverage in Intellij

970 views
Skip to first unread message

Mike

unread,
May 12, 2009, 12:30:45 PM5/12/09
to PowerMock
I am using Intellij IDEA 8.0.1 with emma to collect code coverage
statistics.

I have a legacy class with tests that show about 60% coverage and am
attempting to improve its code coverage. Since the untested methods
make static calls, I am trying to use PowerMock to test those methods.

When I add one test using PowerMock, the test runs perfectly -- but
code coverage for the entire class is reported as ZERO.

Has anyone successfully used PowerMock with Intellij/emma and
successfully collected code coverage statistics? Is there some IDE
configuration required?

Mike

Jan Kronquist

unread,
May 13, 2009, 10:38:36 AM5/13/09
to powe...@googlegroups.com
Hi

I can't get the emma plugin to work in IntelliJ and the Emma website
list the plugin as no longer supported. I can also see that the plugin
is using a quite old version of Emma.

However, I also tried running Emma from maven and I successfully got
the code coverage. However, there was a glitch with the report
generation. For some reason the maven plugin complains when generating
a report. The instrumentation and code coverage measurements are
performed. From the code coverage measurements I was able to generate
a coverage report using Emma command line arguments ie

java -cp emma-2.0.5312/lib/emma.jar emma report -r txt,html -in
target/coverage.em -in coverage.ec -sp src/main/java/

I've also tested cobertura and the maven plugin seems to work without
any problems. However, cobertura seems to be a bit confused with
PowerMock manipulated class files and does not correctly report code
coverage in all cases. For example I had problems getting code
coverage when mocking "new" inside a constructor. (This works
correctly in Emma) Other than that it seems to work fine.

/Jan

Mike

unread,
May 13, 2009, 4:59:18 PM5/13/09
to PowerMock
Emma comes builtin to the 8.x Idea deliverable. When you create a run
profile to run a unit test, there is a tab for code coverage. You can
select Emma or IDEA from there. Neither work with PowerMock.

Also, I have a class which uses the Role object from the Catalina
JAR. When I put in the @RunWith(PowerMockRunner.class) annotation,
somehow the class loaders collide, because the test no longer runs and
a PowerMock reflection error is reported. I remove the @RunWith()
annotation and the test runs fine. So it appears there is a
classloader problem as well.

Have you seen any of this? We have verified the problem on two
separate developer systems here at work.

Mike

On May 13, 8:38 am, Jan Kronquist <jan.kronqu...@gmail.com> wrote:
> Hi
>
> I can't get the emma plugin to work in IntelliJ and the Emma website
> list the plugin as no longer supported. I can also see that the plugin
> is using a quite old version of Emma.
>
> However, I also tried running Emma from maven and I successfully got
> the code coverage. However, there was a glitch with the report
> generation. For some reason the maven plugin complains when generating
> a report. The instrumentation and code coverage measurements are
> performed. From the code coverage measurements I was able to generate
> a coverage report using Emma command line arguments ie
>
> java -cp emma-2.0.5312/lib/emma.jar emma report -r txt,html -in
> target/coverage.em -in coverage.ec -sp src/main/java/
>
> I've also tested cobertura and the maven plugin seems to work without
> any problems. However, cobertura seems to be a bit confused with
> PowerMock manipulated class files and does not correctly report code
> coverage in all cases. For example I had problems getting code
> coverage when mocking "new" inside a constructor. (This works
> correctly in Emma) Other than that it seems to work fine.
>
> /Jan
>
Message has been deleted

rikardq...@gmail.com

unread,
Jun 24, 2009, 2:52:03 AM6/24/09
to PowerMock
Hi i also have problems running emma with powermock inside idea. I run
Idea 7.0.4.

Stacktrace:
Exception in thread "main" java.lang.Error: EMMA: runtime controller
could not be started, aborting
at com.vladium.emma.rt.RT.reset(RT.java:233)
at com.vladium.emma.rt.RT.<clinit>(RT.java:540)
at com.mytestclassTest.$VRi(mytestclassTest.java)
at com.mytestclassTest.<clinit>(mytestclassTest.java)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance
(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance
(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
at
org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.createTest
(PowerMockJUnit44RunnerDelegateImpl.java:184)
at
org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.invokeTestMethod
(PowerMockJUnit44RunnerDelegateImpl.java:191)
at
org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.runMethods
(PowerMockJUnit44RunnerDelegateImpl.java:159)
at
org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl
$1.run(PowerMockJUnit44RunnerDelegateImpl.java:133)
at org.junit.internal.runners.ClassRoadie.runUnprotected
(ClassRoadie.java:27)
at org.junit.internal.runners.ClassRoadie.runProtected
(ClassRoadie.java:37)
at
org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.run
(PowerMockJUnit44RunnerDelegateImpl.java:131)
at
org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.run
(JUnit4TestSuiteChunkerImpl.java:112)
at
org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.run
(AbstractCommonPowerMockRunner.java:44)
at com.intellij.rt.junit4.Junit4TestMethodAdapter.run
(Junit4TestMethodAdapter.java:58)
at junit.textui.TestRunner.doRun(TestRunner.java:116)
at com.intellij.rt.execution.junit.IdeaTestRunner.doRun
(IdeaTestRunner.java:65)
at junit.textui.TestRunner.doRun(TestRunner.java:109)
at com.intellij.rt.execution.junit.IdeaTestRunner.startRunnerWithArgs
(IdeaTestRunner.java:24)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart
(JUnitStarter.java:118)
at com.intellij.rt.execution.junit.JUnitStarter.main
(JUnitStarter.java:40)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:
90)

Anyone have clue? is this a class loader problem or something else.

Cheers Rikard


On 13 Maj, 22:59, Mike <mjharri...@gmail.com> wrote:
> Emmacomes builtin to the 8.x Idea deliverable.  When you create a run
> profile to run a unit test, there is a tab for code coverage.  You can
> selectEmmaor IDEA from there. Neither work with PowerMock.
>
> Also, I have a class which uses the Role object from the Catalina
> JAR.  When I put in the @RunWith(PowerMockRunner.class) annotation,
> somehow the class loaders collide, because the test no longer runs and
> a PowerMock reflection error is reported.  I remove the @RunWith()
> annotation and the test runs fine.  So it appears there is a
> classloader problem as well.
>
> Have you seen any of this?  We have verified the problem on two
> separate developer systems here at work.
>
> Mike
>
> On May 13, 8:38 am, Jan Kronquist <jan.kronqu...@gmail.com> wrote:
>
>
>
> > Hi
>
> > I can't get theemmaplugin to work in IntelliJ and theEmmawebsite
> > list the plugin as no longer supported. I can also see that the plugin
> > is using a quite old version ofEmma.
>
> > However, I also tried runningEmmafrom maven and I successfully got
> > the code coverage. However, there was a glitch with the report
> > generation. For some reason the maven plugin complains when generating
> > a report. The instrumentation and code coverage measurements are
> > performed. From the code coverage measurements I was able to generate
> > a coverage report usingEmmacommand line arguments ie
>
> > java -cpemma-2.0.5312/lib/emma.jaremmareport -r txt,html -in
> > target/coverage.em -in coverage.ec -sp src/main/java/
>
> > I've also tested cobertura and the maven plugin seems to work without
> > any problems. However, cobertura seems to be a bit confused with
> > PowerMock manipulated class files and does not correctly report code
> > coverage in all cases. For example I had problems getting code
> > coverage when mocking "new" inside a constructor. (This works
> > correctly inEmma) Other than that it seems to work fine.
>
> > /Jan
>
> > On Tue, May 12, 2009 at 6:30 PM, Mike <mjharri...@gmail.com> wrote:
>
> > > I am using Intellij IDEA 8.0.1 withemmato collect code coverage
Reply all
Reply to author
Forward
0 new messages