sonar code coverage is not displaying - sonarqube

Which plug-in needs to installed to get the code coverage metrics in sonar reports? It was working fine for previous version(3.7.3) and now I am using 4.1.1 I can only see the unit test coverage. I need both if possible.

Related

Does SonarQube always require an external code coverage tool to show coverage on sonar server?

Does SonarQube always require an external code coverage tool like jacoco (Java), Coverage (python), gcov (c/c++), in order to show coverage on a sonar server?
SonarQube by itself doesn't do any coverage. Its the job for other tools like jacoco and others.
However SonarQube can gather the "results" relevant to the project quality (of course including coverage as an important code quality metric) of the build and allows tracking of the quality over time.
Usually you run coverage tool first, it "adjusts" the code, then you run the tests in the build. Coverage tool creates some results, and only after that you run sonar plugin that processes the results and sends to the sonar qube server.
So, to answer your question: Yes, without an external code coverage tool, sonar won't produce any coverage results, and no, it doesn't have a "default, built-in" coverage tool

Export explicit Jacoco it report to sonarqube 6.7

I'm not able to see the Integration Tests in new sonarqube 6.7 version, here is what I'm doing,
Run Sonarqube task with Gradle to generate the report along with code coverage.
Here, Sonarqube is by default invoking test task and using the test.exec file from build/jacoco generated by Jacoco plugin.
However, I've a task depends on the test task to place an integrationTest.exec report in the build/jacoco as the integrations tests are run outside build(for some reason)
Though I place the integrationTest.exec file explicitly while Sonarqube execution it is still not considering the report and due to which I do not see any change in the coverage computed also I do not see Integration Tests section under coverage like I see Unit Tests.
Firstly, I would like to understand that whether is it feasible to export the integration tests result like I did above or not?
Second, is the latest Sonarqube having the capability to show integration tests report in the coverage section?
Your comments would help me.
Thanks in advance!

Unit Test Coverage not visible in Sonarqube

I am running analysis on my solution which contains a Unit Test project just like any other projects . But there is 'No Data' in Unit Test Coverage Widgets .But I can see the analysis if I open respective folder/file of UT . How can I see Unit Test Coverage details by adding widget.
I am not using any of these tools...i am running analysis with sonar scanner.
SonarQube doesn't generate code coverage data. It displays data provided by reports generated by other tools. You have to configure and execute any code coverage tool and then scanner will upload results to the server.
See how to do it for C#: Code Coverage Results Import (C#, VB.NET)
More about code coverage: Seeing Coverage

How to force code coverage to Zero?

I have several java projects with no unit test cases. When I try to analyse these projects using SonarQube I am unable to get unit test code coverage because it doesn't have any test cases. As per my research I saw that I can force it to show it as zero if there are no unit test cases. The official Jacoco Java documentation mentions sonar.jacoco.reportMissing.force.zero=true.
My SonarQube analysis will be done using maven builds and SonarQube 5.6.6 and sonar-java 4.11.0.10660.
How can I set this parameter in maven so that it can show as zero unit test cases in my coverage?
From version 6.2 SonarQube does this automatically where the behavior is supported by the analyzers. Before that version, availability of the feature is spotty and not entirely reliable. For best results you should upgrade SonarQube.
That said, you can set that property on the analysis command line like so:
mvn sonar:sonar -Dsonar.jacoco.reportMissing.force.zero=true
Or by setting a property in your pom, as shown in the docs
Update 16 Dec 2019
Most language analyzers now calculate Executable Lines, so files omitted from the coverage report are included in calculations anyway. But that only kicks in if you provide coverage reports. No coverage reports -> no coverage metrics at all.

SonarQube not picking up Cobertura code coverage

I am analysing a Java project that has been unit tested and Cobertura coverage.xml reported. I am using SonarQube 4.1.1 and latest Sonar Runner. I have successfully imported Cobertura coverage results to Sonar 3.2 and Ant analyzer, but with this new version I am running into problems. In the new Sonar analysis execution (through Jenkins) I see no reference in logs that it would have started any Cobertura engine or anything. My settings in Runner Jenkins project:
sonar.dynamicAnalysis=reuseReports
sonar.java.coveragePlugin=cobertura
sonar.cobertura.reportPath=[mypath]/coverage.xml
sonar.junit.reportsPath=[mypath]/
No mentioning of Cobertura in the analysis output (except my own property values) and SonarQube page shows "-" in coverage report. Unit test results are shown fine.
I have also added all source, bin, and test directories. Any ideas? Thanks.
Update
I wonder if the reason why Cobertura coverage is not reported on SonarQube page, is because in Jenkins my SonarQube project clones (Clone plugin) the workspace from a previous Project build? If the coverage.xml file contains static paths, then maybe it goes wrong somehow.
Ok the solution was quite obvious. SonarCube 4.1.1 does not come with Cobertura preinstalled, so I installed it and now it works :) Maybe it was preinstalled in 3.2 version, I can't remember.
For any "reuse reports" feature in SonarQube (may it be for code coverage, test execution or any other third-party tool that generates a intermediate report), the report must be generated based on the same source files (in terms of file system location) than the ones that will be used for the SonarQube analysis. Otherwise the SonarQube plugins won't be able to match paths from the reports with paths of the analyzed sources.
So you guessed it right: cloning the workspace and running the SonarQube analysis on this clone is the reason why the coverage can't be computed.
The root cause of this problem is that SonarQube does not support Cobertura format and you need OpenCover, or dotCover format. Using reportgenerator is one of the solutions but it's unnecessary complicated: you can make "dotnet test" command to return the report in Opencover format by passing special parameter and then pick up the Opencover report.
Use
dotnet test --collect:"XPlat Code Coverage" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=cobertura,opencover
to get two reports: one in OpenCover format for SonarQube and default Cobertura for Azure DevOps.
Now you can specify the path to OpenCover report in SonarQubePrepare task.
There is also detailed article on this here

Resources