Generic test plugin ignores file - sonarqube

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

Related

How to configure a sonar-project.properties file for code coverage?

Current my scanner is running through and only scanning the parent and skipping the rest of my nested files. If I run sonarlint (using the cli and specifying some test and source files) , it tries to analyze 37k files instead of the few I need. I have been able to skip ~3k files by adding the <sonar.skip>true</sonar.skip> property to a pom file. However, I still can't configure the project to run across certain sub-folders and print out some kind of code coverage test. (Is JaCoCo needed for the latest version(6.3,0)? Or can code-coverage be handled through some configuration?).
If Sonar seems to be analyzing too many files, it is probably because you had not set the sonar.sources=src/main/java in your sonar-project.properties file, so it defaults to the basedir and includes everything.
SonarQube can't do code-coverage itself, it just reports on coverage-reports from a tool like JaCoCo. It is funny they don't clarify these things in https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner --but with enough digging, you can find good info on that site.

No LOC or Bugs picked up by SonarQube runner

I am using sonar-web-frontend-plugin
I have the following sonar-project.properties file which is located at this path
E:\agent2\test\sonar-project.properties
sonar.projectKey=Test
sonar.projectName=Test
sonar.projectVersion=1.0
sonar.sources=src/app
sonar.sourceEncoding=UTF-8
I have my source code in the following location
E:\agent2\test\src\app
My runner is located here
E:\agent2\test\.sonarqube\bin\sonar-scanner-2.8\bin\
and I am running the following in cmd E:\agent2\test>
E:\agent2\test\.sonarqube\bin\sonar-scanner-2.8\bin\sonar-runner -Dproject.settings= E:\agent2\test\sonar-project.properties -X
It is all running fine but no issues are being reported and no LOC are being picked up in the log it says the following
Calculating CPD for 0 Files
So it does not actually seems to analyse anything, I know there are issues because when i run TSlint locally i get issues found
Your analysis setup looks okay.
It is very likely that you don't have the relevant language plugin installed on your SonarQube instance. Either that, or your code is contained in files with unrecognized extensions.
Each language plugin tells SonarQube scanner "I'm interested in files with these extensions:..."
The fact that the analysis is over "0 Files" indicates that no file extensions were recognized.

Failed to publish TestNG Report in Jenkins

I have used Maven project with Selenium & TestNG to create automated scripts which I want to execute from Jenkins. In Jenkins I have added the TestNG plugin to publish the TestNG report. But it is not getting displayed. I'm getting the below mentioned error.
Error:
TestNG Reports Processing: START
Looking for TestNG results report in workspace using pattern: /target/surefire-reports/testng-results.xml
Did not find any matching files.
Finished: SUCCESS
Actual path of the TestNG report file:
E:\STUDY_MATERIAL\JAVA\WORKSPACE\SeleneniumFrameWork\target\surefire-reports\testng-results.xml
I have tried the following options but didn't work out for me.
Tried giving the full path of the TestNG report. Forward ans backward slash in the pattern.
I have tried different other options by changing the TestNG result file path but it's working for me.
Please share some inputs on how to resolve this issue.
"testng-results.xml" file is available in workspace. But it's failed to display the report. I have attached screenshot of Jenkins workspace and Console Output.
Note: I am using Jenkins 2.7.0 in Windows 10.
Jenkins Workspace
I have attached the Job configuration details of Jenkins.
Job Configuration Details
Few checkpoints :
1. Check if testng is producing this file at the specified location : /target/surefire-reports/testng-results.xml
2. TestNG needs to be configured to generate xml report
If this file is there, pass path in file locator as :
target/surefire-reports/testng-results.xml
Hopefully, you will get results on jenkins if everything mentioned above is correct.

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.

set configuration properties in sonar

Maybe, this question is silly but I'm very new. I try to search without luck.
I got two errors when building maven project with sonar:
No information about coverage per test.
Although I had test code and these testing classes cover the code.
The global property 'sonar.doxygen.deploymentPath' is not set. Set it in SONAR and run another analysis.
I dont know it should be set where in sonar server. I set in web.xml or sonar-server.properties but it does not work.
Thanks.
About the first warning message this is not an error but a warning : since Sonar 3.5 this is possible to get the code coverage relating to each unit test. Here the message just says that this feature is not activated which is expected by default. Nevertheless I do agree that this warning message can be misleading.
About the second error message, I don't know the doxygen plugin but the message seems to be pretty clear : the sonar.doxygen.deploymentPath property has not be defined. See the plugin documentation : http://docs.codehaus.org/display/SONAR/Doxygen+Plugin.
Two things:
There is no war folder anymore since the sonarqube has given up tomcat support
The doxygen plugin is not implemented to upload the files in to the sonarqube server &/ installation, which means it only can be done by referencing the path inside your installation, e.g.:
run "mvn install sonar:sonar" in your project "/root/test.example.sonar.com"
in sonarqube set the cfg-key "sonar.doxygen.deploymentPath" the value: "/root/sonarqube-4.1.1/web/" and the cfg-key "sonar.doxygen.deploymentUrl" the value: "http://:9000"
have fun with your doxygen
Remember that the plugin will only be run through your mvn cmd, refreshing the page only will not do the job, you will have to analyse again after each cfg set :/
Check the file system and folder permission

Resources