SonarQube coverage on multi-modules project - sonarqube

I have a multi-modules project in SonarQube. One of the modules did not have any unit-test so far. Now that I added a unit-test in this module, the overall coverage of the project decreased! Does it mean that when a module has no test, it is not included at all in the global coverage calculation?

You have correctly deduced the situation: If there's no coverage at all, it's excluded from the calculations by default. On a language-by-language basis (available in Java) "force coverage to zero" functionality is available.

Related

How can I set-up Maven to create Jacoco coverage for tests for source code another module?

I have a multi-module Maven project. Many of the tests are in the conventional directory (src/test/java) but about 60% are in single module.
By default, Jacoco does not create coverage for those tests.
I'd like the tests in the single module to contribute to coverage.
Nb. We collects coverage in Sonar.
To fix this, set the following configuration item:
<inclNoLocationClasses>true</inclNoLocationClasses>

Module level sonar analysis in maven Multi Module project

While building from my Parent module, the code coverage and sonar anslysis happens fine. Since Sonar does aggregation of code coverage of all sub modules.
However, When I build my sub-module for code coverage, the analysis is not updated back in my Parent project.
Is there a way to tweak the aggregation both ways, i.e. When Parent build happens or when an individual Module builds independently. I don't want to run the whole parent project everytime, to capture the code coverage analysis in sonar.
My parent pom.xml consists of all sonar,jacoco configurations and other modules inherit them.
<sonar.jacoco.reportPaths>${project.basedir}/../target/*ut-jacoco.exec</sonar.jacoco.reportPaths>
And each module generates its own moduleX-ut-jacoco.exec.
Thanks #khmarbaise for guidance. It took a while to understand the behavior but its indeed a learning.
After Module is build with test-case execution using
mvn clean install
A separate sonr analysis is needed to be run on parent project.
mvn sonar:sonar
This subsequent sonar analysis helped me update coverage and other metrics on Parent porject as well as at Module level.

Integration Test Code Coverage using jacoco and maven

I have a maven test project which tests our dev code. These 2 are different maven projects.
Test project access dev project via maven dependency.
I want to measure integration test code coverage against dev project using jacoco and maven plugin.
Previously I have done it using jacoco and sonar where test code generates jacoco.exec file and then I manually built dev project passing jacoc.exec as arg in jenkins and get code coverage report.
I was not basically looking for 100% automated way of doing this.
Have read couple of articles which uses jacoco with maven but all those uses single project.
Appreciate any help/pointer.
Thanks
The 'dirty trick' here is to accumulate Jacoco coverage reports. As you have different projects there is no legal way to do this as by design maven projects are to be built without direct dependency.
But in real world nothing is ideal:
You point JaCoco report file with fixed path. By the way you can do it relatively to your Maven repository which is pretty clean approach.
You build your projects in 2 phases: first phase build all projects running all possible tests. It's better to have separate JaCoco report files per unit and integration tests. But they should be the same among projects and projects shall be configured to accumulate reports.
Doing second pass you run your mvn sonar:sonar magics. This will bring you 2 sonar projects (as I understand now you have the same picture) but coverage will be much more precise. The key is unified reports calculated on previous stage.
Here is complete enough illustration of this idea and lot of references to more simple projects. And here is another question which illustrates idea.
Hope this helps. I do the same approach for my multi-module projects to get coverage for 'lower layer' modules when doing tests for 'higher layer' ones.

Maven Multi-Module plus Extrenal Tests plus JaCoCo plus Sonar

On our company we have the several modules on project and each module has several unit tests, but we have system tests that based on classes and not modules. Our system tests use several classes of each module (not all). We cannot calculate intergration coverage and unit coverage of this tests. We want to merge results of system tests to calculate the coverage of all probuct.
Anyone have any idea how we can do this? Anyone can provide any tutorial with examples?
You can find a sample application that reproduces this case here: https://github.com/SonarSource/sonar-examples/tree/master/projects/code-coverage/combined%20ut-it/combined-ut-it-multimodule-maven-jacoco
This should help you.

COBERTURA configuration within SONAR

I am using SONAR for Code Quality checks of my projects. In one project I would like to know the code coverage of a library which is included in the classpath (maven dependency).
Is it possible to configure SONAR (with embedded COBERTURA) to also instrument the specific library for code coverage analysis? As cobertura instruments the bytecode this should be possible but I do not know if it is supported by cobertura (even indepentend from SONAR).
Any hints are welcome.
Regards
Klaus
You would have to set up cobertura(maven target) yourself and import the results(See dynamic analysis)
sonar.dynamicAnalysis=reuseReports
sonar.cobertura.reportPath=PATH_TO_RESULT
But I will not help much:
you would need the src files of the jar to see the coverage, otherwise you would just get % numbers and I'm not even sure sonar will show the extra covered files
the coverage for your whole project will always include the % of the library, so it will go down
It is better to test each project with its own unit tests on its own.

Resources