SonarQube server shows zero unit tests - sonarqube

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.

Related

Incorrect Java coverage analysis result when executing the analysis via Jenkins

We run Sonar coverage analysis for multi-module Java projects in a Jenkins environment using the sonar-maven-plugin. We noticed that the coverage analysis results displayed on our Sonar dashboard are not correct for a handful of source files. One odd finding from my investigation is that I when I run the analysis from my local development laptop, the coverage analysis is correct (Sonar dashboard updated with the correct coverage percentages for those source files). Has anyone encountered any issues like this before?
Clarification:
The differences in the coverages are mostly between 0 and non-zero percent coverage. But I also see a couple of instances where the difference is between non-zero and non-zero percent coverage. Also, the differences correspond to source files from random packages, not any specific package. We are encountering this issue across various Sonar projects as well (so not just an issue specific to one of our Sonar project).
Also, when I import the Jacoco exec data file into Eclipse (using eclemma plugin), I do see the correct coverage percentages (non-zero). Furthermore, the coverage result when running the analysis locally can also be incorrect when compared with the result as interpreted by the EclEmma plugin). So, now it seems the analysis results may be incorrect regardless of which environments I run the analysis from (assuming the analysis result from EclEmma is correct).
Not sure why the coverage results is wrong only for a handful of the source files. I have compared both the client-side console logs and server side (Sonar server) logs -- but did not find any clues (no indication of error, both analysis were successful). I have also compared the coverages-xxx.pb files' sizes from the batch-report folder, but did not find any differences either.
Thanks in advance to anyone with suggestions on how I can troubleshoot this further! Please let me know if any additional information regarding the execution environments would be helpful.
Thanks,
Thinh
SONAR ENVIRONMENT:
- sonar-maven-plugin version: 3.3.0.603
- SonarQube version: 5.6.6
- sonar.java.source: 1.8
- sonar.java.target: 1.8
- sonar.sourceEncoding: UTF-8
SonarQube plugins:
- Findbugs 3.5 (findbugs)
- SonarJava 4.11.0.10660 (java)
- Git 1.2 (scmgit)
JENKINS ENVIRONMENT:
- Jenkins version: CloudBees Jenkins Enterprise 2.46.3.2-rolling
- Maven version: 3.1.1
- Java version: OpenJDK 64-bit Server 1.8.0_141
- Slave OS: 64-bit, CentOS (Red Hat 4.4.7-11), Linux version
2.6.32-504.12.2.el6.x86_64
LOCAL LAPTOP ENVIRONMENT:
- Maven version: 3.1.1
- Java version: Java HotSpot(TM) 64-Bit Server VM
(build 1.8.0_60-b27)
- OS: macOS Sierra, version 10.12.5

How to get the sonar-report.json file created with sonarqube?

I am runnig Sonarqube 5.3 and has integrated it with Jenkins. I want to post Sonareqube issues as Gerrit comments.
Then I need to specify the path to and name of the data generated from sonarqube, e.g. build/sonar/sonar-report.json
The file sonar-report.json is not generated and I have found some setting for Sonarqube that shouold make sonareqube create the file.
sonar.report.export.path=sonar-report.json
sonar.issuesReport.html.enable=true
sonar.issuesReport.json.enable=true
sonar.issuesReport.console.enable=true
I have tried to set these in the file
<sonar-installation-directory>/conf/sonar.properties
I have restarted the Sonare service and restarted the computer but the sonar-report.json file is still not created.
Those properties are not meant to be configured on the server side, they are passed on the scanner side, and are valid only for analysis in preview mode (by the way no need for sonar.issuesReport.json.enable). That's what SonarLint for Command Line is about.
Why preview mode ? Because the goal is to analyse a diff (to comment the code review in your case). You don't want a full analysis to be submitted to SonarQube if the code is not yet pushed to the repo.
Example:
$ sonar-runner -Dsonar.analysis.mode=preview -Dsonar.issuesReport.html.enable=true -Dsonar.report.export.path=report.json -Dsonar.host.url=http://localhost:9000
[...]
$ ls .sonar/
issues-report report.json
(careful with the JSON report, looks like it will ultimately be removed, see SONAR-7247)
P.S.: I guess you might be using the sonar-gerrit Jenkins plugin, which is essentially saying the same thing:
This plugin is intended to work with report provided by SonarQube running on your project in preview mode

Generic test plugin ignores file

I try to use the generic test plugin. I have the unittest.xml file with an absolute path
<file path="/Users/emerson/dev/sonar/project/workspace/components/triage/src/assets/test/unit/tests/controllers/controller.coffee">
the coffee script got compiled into js and unit tests were executed with the unittest.xml as result.
When I add this to my sonar build via the sonar.genericcoverage.unitTestReportPaths, it does recognise the unittest.xml, but does nothing.
The log says
[sonar:sonar] 14:32:55.108 INFO - imported unit test data for 0 files
[sonar:sonar] 14:32:55.109 INFO - unit test data ignored for 1 unknown files, including:
and then the path to the file named in the unittest.xml
The path is valid, why does it not recognise it ? Neither the coffee script nor the compiled js are part of the sonar build, is it therefore ?
As there is no support of coffee script with sonar, my hope was to at least include the unittest results in sonar.
Can someone explain whether it is possible and what should be written into the path field in the unittest.xml ?¨
Thanks for any clarification
Indeed the files need to be indexed in SonarQube in order to import test data.
You can set sonar.import_unknown_files to true with SonarQube 5.1+ to have all files indexed by SonarQube.
http://docs.sonarqube.org/display/SONAR/Analyzing+Source+Code#AnalyzingSourceCode-Unrecognizedfiles

How to configure SCM support for MSBuild SonarQube Runner?

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.

Having trouble getting started with SonarQube

I installed SonarQube and sonar-runner, and the web server seems to work just fine as I can browse it. I tried to keep things as simple as I could, I put the "sonar-project.properties" file in my project's source folder and gave . as the sonar.sources path. After doing so, the console output reported success and the web page listed my project and last analysis date, but when I went into the "Compare" tool to look at statistics it showed all items as blank, except for issues for which is displayed the number 0.
I edited the sonar-project.properties file to give the full path (instead of a relative current directory path of .) to my project's source code, replacing backslashes with forward slashes, and ran the sonar-runner command again from the command line while the working directory was the path of my source folder. It again reported success and when I reloaded the web page, it gave an updated last analysis date, but again no issues were reported and the statistics were all blank.
I have no idea what I'm doing wrong, the Sonar log only reports the installation and starting of the Windows service, and it doesn't indicate any problems. The StartNTService script starts the service without error, but the StartSonar script reports "jvm 1 | WrapperSimpleApp: Encountered an error running main: org.apache.catalina.LifecycleException: Failed to initialize component [StandardServer[-1]]". I don't know if that's relevant for the way I'm using SonarQube as a Windows service. I'm using pretty much all default configuration except I edited the sonar-runner.properties file by un-commented these lines:
sonar.host.url=http://localhost:9000
...
sonar.sourceEncoding=UTF-8
If anybody can help me figure out how to get this to work, I would greatly appreciate it. I am running Windows XP Pro x64 SP2 and Java 1.7.0_51 (32 bit). On my first attempt I did incorrectly use the 64 bit service install/launch scripts but when the console output indicated it didn't match the JVM architecture, I stopped and uninstalled the service and installed and launched the 32 bit service.
Edit: I'm using Sonarqube version 4.2 and Sonar-runner version 2.3.
By default, SonarQube is packaged with the Java ecosystem (Java, Checkstyle, PMD), but for C/C++ you will have to install one of the plugins that support analysis of these languages.
There is a commercial C++ plugin from SonarSource and a free Community Plugin.

Resources