这是Eclemma(JaCoCo)的已知问题。基本上两个库都修改字节码,但Mockito会在运行时修改它,这会产生一个不同的二进制文件。 JaCoCo显然使用通过hashMap来跟踪它正在观看的类,其hashcode是由类定义导出的,所以在Mockito修改类之后,哈希码将不同,所以JaCoco不再在其内部地图中找到类。
更详细地讨论:
使用JUnit和Powermock的Emma代码覆盖
http:/ /code.google/p/powermock/issues/detail?id=402
I met a problem of using EclEmma plugin in Eclipse. It doesn't show code coverage when I use annotation @RunWith passing (PowerMockRunner.class) as an argument. In case of using (MockitoJUnitRunner.class) everything is fine. Waiting for your suggestions? :)
解决方案This is a known problem with Eclemma (JaCoCo). Basically both libraries modify byte code but Mockito modifies it during runtime which produces a different binary .class file. JaCoCo apparently uses keeps track of the classes it's watching via a hashMap whose hashcode is derived by the class definition so the hashcode will be different after Mockito modifies the class so JaCoco can't find the class in it's internal Maps anymore.
Discussed in more detail:
Why EclEmma doesn't coverage code with tests with @RunWith(PowerMockRunner.class)
Emma code coverage with JUnit and Powermock
code.google/p/powermock/issues/detail?id=402
更多推荐
EclEmma代码覆盖插件和PowerMockRunner
发布评论