Unable to get Jacoco to work with Powermockito using offline instrumentation
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
Given that Jacoco doesn't play nicely with PowerMockito when instrumenting "on the fly", I've been trying to configure offline instrumentation in the hope this will give me proper unit test coverage for classes that use PowerMockito.
I've setup my pom as below but I still get zero % coverage on my test class. Any help much appreciated as it's driving me slowly bonkers!
4.0.0com.stackoverflowq23598722.0-SNAPSHOTq2359872${org.jmockit:jmockit:jar}org.jmockitjmockit1.11generate-sourcesorg.apache.maven.pluginsmaven-dependency-plugin2.3propertiesorg.codehaus.mojoexec-maven-plugin1.2execgenerate-sourcesechopath to jar=${org.jmockit:jmockit:jar}my.lib=${my.lib}
回答4:
I was also facing the same issue. I was able to generate report partially. I have used both these tags for my test cases @RunWith(PowerMockRunner.class) @PrepareForTest({}). And the report was not getting generated for the test cases where i used the above mentioned tags. But for one of the test case there was only this tag @RunWith(PowerMockRunner.class). Somehow the report was getting generated for that case. And also i have never used offline instrumentation. When i tried using the offline instrumentation i was getting error saying that the class was already instrumented. I tried various scenarios and followed various links but could not generate the report. Finally as per the above comment i upgraded my version of powermock from 1.5.5 to 1.6.5 and i was able to generate the report. Following is my pom.xml entry
And upgraded my powermock version from 1.5.5 to 1.6.5 . Finally i could see my report generation for the classes where i used the following tags in my test cases @RunWith(PowerMockRunner.class) @PrepareForTest({})
回答5:
I ended up using offline instrumentation and Jacoco (similar to what you have done) in conjunction with sonar and I was able to get the coverage numbers from that.
回答6:
I used Jacoco offline instrumentation and after execution of test restore ed original classes with help of "restore-instrumented-classes" goal. My JaCoCo configuration look like this: