具有Jacoco代码覆盖率的PowerMockito [英] PowerMockito with Jacoco Code Coverage

查看:180
本文介绍了具有Jacoco代码覆盖率的PowerMockito的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中,我们使用powermockito来实现代码覆盖率的jacoco api.看来我们使用了 @preparefortest({xyzimpl.class,abcd.class})批注.在代码覆盖率上,不包括xyzimpl.java代码覆盖率.有什么办法可以解决上述情况的代码覆盖率.在其他链接中已读过,如果我们取消在 @preparefortest 批注内测试的类,则上述批注将不会覆盖代码.

In my project we using powermockito, for codecoverage jacoco api. Seens we we use @preparefortest({xyzimpl.class,abcd.class}) annotation. On code coverage, xyzimpl.java code coverage is not covered. is there any work around to get codecoverage for above situation. Have read in other link say above annotation will not get codecoverage if we decleare class to be tested inside @preparefortest annotation.

推荐答案

他们的

Their documentation is pretty clear: it doesn't work (unless you get their "offline" instrumentation work - for which I have not seen working examples).

由于其性质,PowerMock(ito)在处理代码覆盖方面已有很长的历史.请记住:@PrepareForTest所做的是:用PowerMock 生成的替换您的 product 字节代码.

Due to its nature, PowerMock(ito) has a long history of not working with code coverage. Keep in mind: what @PrepareForTest is doing is: replace your product byte code with something that PowerMock generates.

从这种意义上讲,您只有以下选项:

In that sense, you only have these options:

  • 如果您绝对需要模拟静态/新调用,则可以尝试使用JMockit(唯一允许模拟对静态/新调用的其他框架)
  • 学习如何编写 testable 代码-并完全避免使用此类特殊"模拟框架.这甚至可以提高您的产品质量.
  • if you absolutely need to mock static/new calls, then you could try to use JMockit (the only other framework that allows mocking calls to static/new)
  • learn how to write testable code - and avoid the need for such "special" mocking frameworks altogether. This will even improve the quality of your product.

这篇关于具有Jacoco代码覆盖率的PowerMockito的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆