JaCoCo Unit test coverage is reflected as Overall Coverage - sonarqube

I'm using SonarQube 4.5.4, and the SonarQube Runner version is 2.4.
I have defined the sonar.jacoco.reportPath=jacoco/jacoco-ut.exec (the result of junit4 ant task which integrated the jacoco as coverage tool) in the sonar-project.properties file.
The exec file looks fine, it's contains all the coverage information per test, I've imported it with the EclEmma 2.3.2.201409141915 and all the coverage information is there.
In the SonarQube dashboard it's reflecting in strange way:
The cevarage is taken as Overall / IT coverage, instead of UT coverage. and the UT coverage is missing, BTW also the duplication is set to 0% (and it's not true)
from Sonar log it's looks like this:
08:24:34.604 INFO - Sensor SurefireSensor done: 713 ms
08:24:34.604 INFO - Sensor JaCoCoOverallSensor...
08:24:35.140 INFO - Analysing /ibmshome/cc/cctlg/sonar/sonar/ens-14023/./.sonar/ATT_MO_API_TlgServer_ATT_TlgServer_module/jacoco-overall.exec
08:24:52.505 INFO - No information about coverage per test.
08:24:52.505 INFO - Sensor JaCoCoOverallSensor done: 17901 ms
08:24:52.505 INFO - Sensor CoberturaSensor...
08:24:52.506 WARN - Cobertura report not found at /ibmshome/ibms/ibms/target/site/cobertura/coverage.xml
08:24:52.506 INFO - Sensor CoberturaSensor done: 1 ms
08:24:52.506 INFO - Sensor JaCoCoSensor...
08:24:52.815 INFO - Analysing /ibmshome/ibms/ibms/ccirp/proj/sbmsIrd1000/jacoco/jacoco-ut.exec
08:25:04.966 INFO - No information about coverage per test.
08:25:04.966 INFO - Sensor JaCoCoSensor done: 12460 ms
I'm looking for solution for a long time, also tried to change properties and adding sonar.jacoco.itReportPath as dummy, and also getting the same result.

You are seeing overall coverage in SonarQube because you may have the widget for Integration test enabled/set. It's not possible that you are seeing 0% in UT or IT tests but Overall is showing some valid % other than 0.
As per the snapshot you pasted, it seems like you are NOT setting sonar.tests=src/test/java or sonar.java.tests=some/test/java i.e. some valid folder value where all your test source code reside.
For getting the coverage, make sure you set either sonar.jacoco.reportPath=full/relative/path/to/the/jacoco-ut-file.exec and also set the sonar.sources, sonar.tests, sonar.jacoco.itReportPath=full/relative/path/to/jacoco-nonUT-actually-IT.exec file
NOTE: With the newer versions of SonarQube, most of the properties now have java/language name embedded in the properties i.e. sonar.binaries may now be sonar.java.binaries or sonar.groovy.binaries
See setting sonar.java.sources, sonar.java.tests, sonar.java.binaries, sonar.jacoco.reportPath but these will work as it's sonar.jacoco.itReportPath to the correct values helps!
Also, try these settings on a new project if for some reason your project in SonarQube is corrupt and now showing valid data after each evaluation.

Related

Sonarqube coverage 0% in react js

I have written some unit tests in jest. All of them are successful. Able to view test coverage report generated by jest
But my sonarqube dashboard always shows 0% on coverage but unit tests are being detected.
I am using jest-sonar-reporter for sonar consumable format generation of reports.
This is my sonar properties file
sonar.projectKey=skyflow-app
sonar.projectName=Skyflow App
sonar.host.url = http://localhost:9000
sonar.projectVersion=1.0
sonar.sourceEncoding=UTF-8
sonar.sources=src
sonar.exclusions=**/node_modules/**,**/*.spec.ts, **/*.stories.tsx
sonar.tests=src
sonar.test.inclusions=**/*.test.tsx,**/*.test.ts
sonar.test.exclusions=**/*.stories.tsx
sonar.ts.tslintconfigpath=tslint.json
sonar.testExecutionReportPaths=testResults/sonar-report.xml
# sonar.coverageReportPaths = coverage/lcov.info
sonar.javascript.lcov.reportPaths = coverage/lcov.info
Please let me know where i am going wrong.
A dumb mistake from myside.
Replacing sonar.javascript.lcov.reportPaths with
sonar.typescript.lcov.reportPaths solved the issue.
can you share console output of the jenkins job?
in my case, jenkins cannot find the coverage report and got log in console output like this :
15:26:37 [ERROR] Coverage report '/home/jenkins/workspace/microservices-pipelines/xxx/target/jacoco.exec' could not be read/imported. Error: {}
15:26:37 java.lang.IllegalStateException: Failed to parse JaCoCo XML report: /home/jenkins/workspace/microservices-pipelines/xxx/target/jacoco.exec

SonarQube: No information about coverage per test, surefire reports and jacoco

I checked almost all similar issues to my question and tried to test them for two days. So, I am asking here:
I am using: SonarQube server 5.6.6 and SonarQube Scanner 3.0.3.778.
the sonar.properties have been set based on this example project: combined-ut-it-sonar-runner-jacoco
For more clarification please check the analysis parameters that I have set for this project:
sonar.sources=src/main/java
sonar.tests=src/test/java
sonar.java.binaries=target/classes
sonar.java.test.binaries=target/test-classes
sonar.jacoco.reportPath=target/coverage-reports/jacoco-ut.exec
sonar.jacoco.itReportPath=target/coverage-reports/jacoco-it.exec
sonar.junit.reportsPath=target/surefire-reports
Log info that I receive:(I put related logs to my parameters here)
INFO: Source paths: src/main/java
INFO: Test paths: src/test/java
INFO: Sensor SurefireSensor
INFO: parsing /home/jenkins-slave/workspace/team/project/target/surefire-reports
INFO: Sensor SurefireSensor (done) | time=382ms
INFO: Sensor JaCoCoSensor
INFO: Analysing /home/jenkins-slave/workspace/team/project/target/coverage-reports/jacoco-ut.exec
INFO: No information about coverage per test.
INFO: Sensor JaCoCoSensor (done) | time=602ms
INFO: Sensor JaCoCoItSensor
INFO: Analysing /home/jenkins-slave/workspace/team/project/target/coverage-reports/jacoco-it.exec
INFO: No information about coverage per test.
INFO: Sensor JaCoCoItSensor (done) | time=326ms
INFO: Sensor JaCoCoOverallSensor
INFO: Analysing /home/jenkins-slave/workspace/team/project/target/coverage-reports/jacoco-ut.exec
INFO: Analysing /home/jenkins-slave/workspace/team/project/target/coverage-reports/jacoco-it.exec
INFO: Analysing /home/jenkins-slave/workspace/team/project/.scannerwork/jacoco-overall.exec
INFO: No information about coverage per test.
INFO: Sensor JaCoCoOverallSensor (done) | time=348ms
Now in the sonarQube, I can see separate results for integration coverage and unit test coverage:
But no details information such as coverage by which unit test. I would like ideally to have information like: https://docs.sonarqube.org/display/SONAR/Seeing+Tests
Now my questions are: since I already pointed surefire reports(a folder that contains surefire xml files reports) correctly as well as jacoco reports, how can I get information about coverage per test? Am I missing something here? I am a little bit confused because I do not know the exact difference between sonar.junit.reportsPath and sonar.surefire.reportsPath? I do not understand completely which one is responsible to provide information for coverage per test: surefire reports or jacoco reports? Based on the log files, it seems that jacoco is responsible for that. Then, what is the surefire reports role in this analysis?
I would appreciate any help.

NUnit results not showing up in SonarQube after import

I can't really see if my NUnit reports are being imported in to the SonarQube report suite while I am analyzing a .NET project with the MSBuild scanner.
I'm running SonarQube 5.4 with the SonarQube scanner for MSBuild 2.0 and C# plugin v5.0 (and other non-related plugins, as well)
d:\buildTools\sonar-runner-for-msbuild\MSBuild.SonarQube.Runner.exe begin
/k:$productKey
/n:$productName
/v:$BuildNumber
/d:sonar.cs.nunit.reportsPaths=$NunitTestOutput
While I'm passing in the correct path for the nunit.xml report, it is not being imported into the report suite on SonarQube:
I navigate to (project home) -> Dashboards -> Custom dashboard (where I have added the Unit Tests Coverage widget) but it has no more information other than the number of tests.
Just to be sure, the log also shows that the analyzer knows about the exact location of the nUnit report, but it shows no sign of failure or success either.
2016.05.11 09:28:09 INFO [o.s.s.c.t.CeWorkerCallableImpl] Execute task | project=[Redacted-project-name] | id=[redacted]
[...]
2016.05.11 09:28:11 INFO [o.s.s.c.s.LogScannerContextStep] Settings for module: [Redacted-module-name]
[...]
2016.05.11 09:28:11 INFO [o.s.s.c.s.LogScannerContextStep] - sonar.cs.fxcop.reportPath=E:\WS\12500236\source\src\[Redacted-module-name].dll.CodeAnalysisLog.xml
2016.05.11 09:28:11 INFO [o.s.s.c.s.LogScannerContextStep] - sonar.cs.nunit.reportsPaths=E:\WS\12500236\_testoutput\nunit.xml
2016.05.11 09:28:11 INFO [o.s.s.c.s.LogScannerContextStep] - sonar.cs.roslyn.reportFilePath=E:\WS\12500236\source\src\[Redacted-module-name].dll.RoslynCA_fixed.json
[...]
2016.05.11 09:28:29 INFO [o.s.s.c.t.CeWorkerCallableImpl] Executed task | project=[Redacted-project-name] | id=[redacted] | time=20328ms
What should I look for? What am I missing?
I was following this guide to import the NUnit report.
NUnit doesn't have coverage built-in. You need to use some other tool for calculating the coverage.
See Sonar's documentation on code coverage results

SonarQube server shows zero unit tests

I’m integrating SonarQube in our build system – I installed sonar-runner-2.4 on our build agents and added the sonar-runner.properties for each solution (to the solution’s folder on TFS).
When running the build I’m executing the sonar-runner after the solution has been compiled on the build agent.
Everything seem to work except for the unit test:
On the build’s log I see that almost 200 tests ran and were completed successfully and in the sonar-runner log I see the following:
14:23:29.808 INFO - 583/583 source files analyzed
14:23:30.809 INFO - Sensor org.sonar.plugins.csharp.squid.CSharpSquidSensor#1a50b87 done: 14937 ms
14:23:30.809 INFO - Sensor org.sonar.plugins.csharp.core.CSharpUnitTestResultsProvider$CSharpUnitTestResultsImportSensor#97edbc...
14:23:30.821 INFO - Sensor org.sonar.plugins.csharp.core.CSharpUnitTestResultsProvider$CSharpUnitTestResultsImportSensor#97edbc done: 12 ms
Which seems ok I guess, but when logging into the sonar server it shows that 0 tests ran.
On the sonar-runner.properties file I set the following value to
sonar.cs.vstest.reportsPaths:
sonar.cs.vstest.reportsPaths=TestResults/*.trx
when in this case there are 3 vstest trx files located in the following local path on the build agent: `
D:\sTFS\22965\Sources\TestResults
` (see TestResults.jpg attached).
Attached is the sonar-runner.properties file.
I also attached a screen capture from the sonarqube server (see SonarServer.jpg attached).
Can you please advise what might be the problem?
You should be seeing some messages like:
INFO - Parsing the Visual Studio Test Results file ...
for each unit test result file that is being parsed, see VisualStudioTestResultsFileParser.java#L34
Can you try to pass an absolute path pattern to sonar.cs.vstest.reportsPaths? My guess is that the issue comes from the relative path.
By the way, the use of the sonar-runner to analyze .NET projects is being deprecated. You'll want to have a look at the MSBuild SonarQube Runner that offers very good integration with Team Foundation Server. See the new C# plugin documentation on SonarSource's Wiki: http://docs.sonarqube.org/display/PLUG/C%23+Plugin
EDIT
I just noticed the package name from your logs org.sonar.plugins.csharp.core.CSharpUnitTestResultsProvider. The .core. was present only in outdated versions of the C# plugin (in the 3.x series), and these versions might not support wildcards in report paths. Please upgrade to the latest version.

How can I integrate Jacoco reports with SonarQube without using maven?

I used Jacoco eclipse plugin to measure unit test coverage and I was able to export a report using it. I want to integrate that report with sonar so I gave the path to it in the project properties file.
My properties file looks like this
# Required metadata
sonar.projectKey=key
sonar.projectName=name
sonar.projectVersion=1.0
sonar.jacoco.reportPath=jacoco.exec
sonar.tests=junit
sonar.dynamicAnalysis=reuseReports
sonar.java.coveragePlugin=jacoco
sonar.jacoco.reportMissing.force.zero=true
# Comma-separated paths to directories with sources (required)
sonar.sources=src
# Comma-separated paths to directories with tests (optional)
sonar.tests=test
# Encoding of the source files
sonar.sourceEncoding=UTF-8
# Language
sonar.language=java
When I executed sonar-runner the following lines were there in the console output
16:23:13.219 INFO - Sensor JaCoCoItSensor...
16:23:13.219 INFO - No JaCoCo analysis of project coverage can be done since there is no class files.
16:23:13.219 INFO - Sensor JaCoCoItSensor done: 0 ms
16:23:13.219 INFO - Sensor JaCoCoOverallSensor...
16:23:13.219 INFO - Sensor JaCoCoOverallSensor done: 0 ms
16:23:13.219 INFO - Sensor JaCoCoSensor...
16:23:13.219 INFO - No JaCoCo analysis of project coverage can be done since there is no class files.
Also the unit test coverage widget indicated "No Data".
Why am I not able to get Sonar to display the coverage results? What is the correct way to do this?
This is my first experience with Jacoco and I'm also new to Sonar, so detailed guides are very much appreciated.
You must specify "sonar.binaries" property that points to the folder where your classes are compiled.

Resources