本地使用ide执行的测试覆盖率明显高于线上使用jacoco动态统计的结果。
本地模拟线上环境执行也得出了相同的结果。
对应的测试用例的确执行了,但没有对应的统计。
分析来看,所有使用了 MockitoJUnitRunner (来自mockito-core/2.8.9,github mockito)运行junit测试的用例都被忽略了
看起来跟PowerMock是相同的问题?
We are going to replace Javassist with ByteBuddy (#727) and it should help to resolve this old issue. But right now there is NO WAY TO USE PowerMock with JaCoCo On-the-fly instrumentation. And no workaround to get code coverage in IDE.
简单来说,大家都是动态搞字节码的,所以我(Jacoco)是没办法知道你(mockito)是怎么搞(bytecode)的。
PowerMock is an open source mocking library for the Java world. It extends the existing mocking frameworks, such as EasyMock and Mockito, to add even more powerful features to them.
java-code-coverage-jacoco-and-mockitojunitrunner——
JaCoCo does not play well with other tools that modify bytecode on-the-fly. JaCoCo needs to see the same classes at runtime than at reporting time (as the warning text says).
A possible (but not really recommended) workaround is to use JaCoCo offline instrumentation.
mockito issues 969问题里认为可以兼容,应该都是只offline模式,直接读取class文件,而不是on-the-fly模式。
Stack Overflow jacoco-mockito-android-tests-zero-coverage-reported
前两个问题链接看起来是有希望兼容的?第三个告诉你目前还不行哈 :(
https://github.com/jacoco/jacoco/issues/193
https://github.com/mockito/mockito/issues/757
https://github.com/jacoco/jacoco/issues/51