PowerMockito禁用声纳分公司的覆盖范围 [英] PowerMockito disables Sonar branch coverage
问题描述
我在测试类中使用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-但声纳中有许多文件显示0覆盖率
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屋!