问题
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