Sonar test coverage does not include indirect classes

♀尐吖头ヾ 提交于 2020-06-27 04:58:47

问题


If I have the below classes (A and B) which are each in a separate module and I create a test for A.doSomething(), Sonar will complain about 0% coverage on B.doSomething() although it is being testing indirectly in TestA. Using Ecclema coverage plugin for eclipse, I can see B.doSomething() is considered as covered.

Is there a reason for why Sonar acts this way? Is there a way to change the behavior of Sonar's code test coverage to include indirectly tested classes?

class A {
    boolean doSomething() {
        return new B().doSomething();
    }
}

class B {
    boolean doSomething() {
        return true;
    }
}

回答1:


You can easily achieve what you want. This is a matter of how you configure JaCoCo so it has little to do with SonarQube. For example in SonarQube Eclipse project we need that since unit tests are in a separate module.

So we have configured JaCoCo to use the same dump file for all modules (by default JaCoCo Maven plugin will use one separate dump per module): https://github.com/SonarSource/sonar-eclipse/blob/master/pom.xml#L373

And then we configured SonarQube JaCoCo plugin to use the same report: https://github.com/SonarSource/sonar-eclipse/blob/master/pom.xml#L357



来源:https://stackoverflow.com/questions/30579555/sonar-test-coverage-does-not-include-indirect-classes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!