PowerMockito 禁用声纳分支覆盖 [英] PowerMockito disables Sonar branch coverage

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

问题描述

我正在为我的测试类使用 PowerMockito 和 @PrepareForTest 注释.当我这样做时,Sonar 说没有一个分支被覆盖.但是,我的其他不使用 PowerMockito 的测试类运行良好.例如:

I'm using PowerMockito and @PrepareForTest annotation for my test class. When I do this, Sonar says none of the branches have been covered. However, my other test classes that don't use PowerMockito works well. For example:

@RunWith(PowerMockRunner.class)
@PrepareForTest({ MyClass.class })
public class MyClassTest {
    //create some mocks and run some tests here
}

有人遇到过同样的问题吗?

Is there anyone encountered with the same problem?

提前致谢.

推荐答案

PowerMockito 和声纳代码覆盖率计算存在一个已知问题,我对此进行了大量研究 - 到今天为止,还没有解决方案.我个人如何处理它 - 尽量避免使用 PowerMockito - 所以尽量少用 static 和 final ,这通常是一个很好的建议,无论如何都要有更多的面向对象的代码.但是,仍有一些情况需要使用 static 和/或 final.对于这些,在这里比较我的答案:cobertura-showing-proper-coverage-but-in-sonar-many-files-showing-0-coverage

There is a known issue with PowerMockito and sonar code coverage calculation, and I did a big research on this - as of today, there is no fix to it. How I personally deal with it - try to avoid the usage of PowerMockito - so use static and final sparsely, which is generally a good advice to have more object oriented code anyway. However, there will still be a few cases were you will need to use static and or final. For these, compare my answer here: cobertura-showing-proper-coverage-but-in-sonar-many-files-showing-0-coverage

这篇关于PowerMockito 禁用声纳分支覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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