`
fanrey
  • 浏览: 254966 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

emma doesn't coverage code with tests with @RunWith(PowerMockRunner.class);

    博客分类:
  • JAVA
 
阅读更多
被测试的class是VINESNodeAddressCollector:

@RunWith(PowerMockRunner.class)
//add following VINESNodeAddressCollector.class will make coverage not work, so comment out.
@PrepareForTest({ApplicationRunner.class/*, VINESNodeAddressCollector.class*/})
@PowerMockIgnore ({"org.apache.log4j.*", "org.apache.commons.logging.*", "org.xml.sax.*"})

网上搜到的答案:http://stackoverflow.com/questions/9726212/why-tclemma-doesnt-coverage-code-with-tests-with-runwithpowermockrunner-class

AFAIK eclEmma, as well as many other coverage systems, modify your .class files to add coverage instructions. Most of these tools do that at "compile time", not at run time.

PowerMock instead, as well as AspectJ LTW and many other systems, manipulate the same bytecode but at "run time":

PowerMock is a framework that extend other mock libraries such as EasyMock with more powerful capabilities. PowerMock uses a custom classloader and bytecode manipulation to enable mocking of static methods, constructors, final classes and methods, private methods, removal of static initializers and more.

I have a similar problem with both eclEmma (various versions) and Cobertura in combination with AspectJ LTW, cause when the runtime modification of .class files happen, it somehow corrupts the modification done previously by the coverage tool.

I don't have yet found a solution, but at least found the symptom.

The right solution would be to debug PowerMock instrumentation and find out where and how it breaks coverage tools. It's quite a problem, for a testing tool, to break coverage tools, since the two are quite often used together
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics