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.
Related
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.
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
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.
I am using SonarQube 5.1 with MSBuild SonarQube Runner for our quality inspection. Currently SCM support is not there although I have already installed TFVC plugin. I get the following log from the analyze process
07:18:22 07:18:22.352 INFO - Sensor SCM Sensor
07:18:22 07:18:22.352 INFO - No SCM system was detected. You can use the 'sonar.scm.provider' property to explicitly specify it.
07:18:22 07:18:22.352 INFO - Sensor SCM Sensor (done) | time=0ms
Then I set the following properties in the general "sonar.properites" file loacated in \sonarqube-5.1.2\conf folder (which I might be doing wrong)
sonar.scm.enabled=true
sonar.scm.provider=tfvc
sonar.tfvc.username=myTFSusername
sonar.tfvc.password.secured=myTFSpassword
I guess these properties should be set in the "sonar-project.properties" file and passed at the time of analysis (correct me if I am wrong). But the problem is since I am using MSBuild SonarQube Runner, sonar-project.properties file is not used anymore and the project properties are passed at the analysis time. If that is the case how should I pass them in?
I searched a lot but could not find a proper solution in this manner and I'd be very glad if someone could help.
Thanks in advance.
Additional properties are passed to the MSBuild SonarQube Runner during its begin phase using the following syntax: /d:key=value.
So, you can pass all of them:
MSBuild.SonarQube.Runner begin /k:... /n:... /v:... /d:sonar.scm.enabled=true /d:sonar.scm.provider=tfvc /d:sonar.tfvc.username=... /d:sonar.tfvc.password.secured=....
Auto-detection of the SCM will work if there is a $tf at the "project base dir" level. That directory is computed as the first ancestor path common to all your *.csproj files. You can see its value following the file generated during the end phase: .sonarqube\out\sonar-project.properties. Look for the sonar.projectBaseDir property value near the end of the file. See https://jira.sonarsource.com/browse/SONARMSBRU-8 for details.
I'm trying to feed sonar with emma results for a multimodule project
mvn sonar:sonar -Dsonar.dynamicAnalysis='true' -Dsonar.core.codeCoveragePlugin=emma -Dsonar.emma.reportPath=target
For each module I get:
instrumentation path processed in 1798 ms
[146 class(es) instrumented, 19 resource(s) copied]
metadata merged into [<module>/target/coverage.em] {in 152 ms}
and later:
[INFO] [12:24:32.514] Sensor EmmaSensor...
[INFO] [12:24:32.514] Parse reports: <module>/target
[WARN] [12:24:32.514] No coverage (*.ec) file found in <module>/target
[INFO] [12:24:35.123] Sensor EmmaSensor done: 2609 ms
So I get 0% coverage in sonar
Why is it trying to find .ec files instead of .em files?
Sonar version is: 3.5.1
Thanks
It would be nice if you mentioned the Sonar version you use.
However I think that the parameter sonar.dynamicAnalysis should have the value of 'reuseReports' and not 'true'
Also make sure that the em files are existing under the target folder
For more information see http://docs.codehaus.org/display/SONAR/Code+Coverage+by+Unit+Tests+for+Java+Project
and
http://docs.codehaus.org/display/SONAR/Emma+Plugin