SonarQube not publishing the PHP unit test report - sonarqube

I installed below SonarQube version in Redhat 6 Serer.
Versions :
SonarQube : 6.3
Sonar Runner : 2.3
Sonar PHP Plugin : 2.10.0.2087
My project creates a PHPUnit Test Report in a Directory called "testreports"
sonar.project.properties:
# Required metadata
sonar.projectKey=Dashboard3
sonar.projectName=Dashboard3
sonar.projectVersion=2.0
#sonar.language=php
#Path to Source
sonar.sources=/pkg/vddfg/oradfg/apache/htdocs/Symfony/src/DB3
sonar.sourceEncoding=UTF-8
sonar.php.tests.reportPath=testReports/get_jfm_bug11s_test.xml
sonar.exclusions=**/Metro-UI-CSS-master/**
My Sonar executed successfully, by updating the line as Analyzing PHPUnit test report: testReports/get_jfm_bug11s_test.xml but in SonarQube dashboard we unable to find the Test Report.
How to fix this issue?

1) Use the JUnit output format for your tests (PHPUnit configuration):
<log type="junit" target="tests.xml"/>
2) Add "sonar.tests" to your Sonar properties:
sonar.tests=/path/to/tests

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

The build is configured to run SonarQube analysis but the SonarQube analysis targets could not be located

I am new to .Net and new to SonarScanner with MS Build. I am looking forward for your help on resolving the error I get when I build the project after sonarscanner-msbuild begin process .
C:\Windows\system32\config\systemprofile\AppData\Local\Microsoft\MSBuild\14.0\Microsoft.Common.targets\ImportBefore\SonarQube.Integration.ImportBefore.targets(62,5): error : The build is configured to run SonarQube analysis but the SonarQube analysis targets could not be located. Project: XYZ.csproj [E:\jenkins\workspace\XYZ\XYZ.csproj]
Tips and clues:
Ensure you have run SonarScanner.MsBuild begin before executing MsBuild
Run MsBuild with /v:diagnostic switch to get detailed troubleshooting log. In the log lookup SonarQubeTargetsPath and SonarQubeTargetFilePath values.
In case of this or another configuration difficulty see my tutorial on how to setup SonarQube in .NET ecosystem: https://blog.pragmasoft.pl/software/2018-10-10-sonarqube-2-setup-environment/

Jacoco Session created Exed shows no Coverage on Sonarqube

I created a Exec via JacocoAgent on my Local machine (For IT-Testing). Now when I try to upload this Exec to sonarqube, it shows no Coverage.
I built an Ant Task which created an html Report and there I saw, that there was definetely coverage generated. I saw it also in the Jacoco Plugin for Eclipse.
Any Suggestions ?
To execute Sonaranalysis I use Gradle with the "sonar.jacoco.reportpaths" property.
The Log says it is able to read the file (I tried it with the exec, which was generated by Unit Tests and it worked)

JavaScript Unit Tests not working on SonarQube

I have below problems with SonarRunner.
SonarQube along with Sonar runner unable to pull junit format xml reports
Unit Tests or Test Coverage widget doesn't show up. It says No Data.
I am following instructions described here
I manually created report file in XML format as described, but still no luck.
Below is the XML file - TEST-Firefox_210_Mac_OS.com.company.BarTest.xml,
<testsuite name="Firefox_210_Mac_OS.com.company.BarTest" errors="0" failures="0" tests="3" time="0.0">
<testcase classname="Firefox_210_Mac_OS.com.company.BarTest" name="testfullName" time="0.0"/>
</testsuite>
To pull the Unit Test execution report to show on sonar dashboard. I have used sample git project from here
and below is my sonar-project.properties,
# project metadata (required)
sonar.projectKey=org.codehaus.sonar:javascript-sonar-runner-jstestdriver
sonar.projectName=JavaScript project with Sonar Runner reusing reports generated by JsTestDriver
sonar.projectVersion=1.0
# path to source directories (required)
sonar.sources=C:/Sonar/sonar-runner-dist-2.4/sonar-runner-2.4/projects/sources
# path to tests source directories (required)
sonar.tests=C:/Sonar/sonar-runner-dist-2.4/sonar-runner-2.4/projects/tests
sonar.javascript.jstestdriver.reportsPath=C:/Sonar/sonar-runner-dist-2.4/sonar-runner-2.4/projects/target/TEST-Firefox_210_Mac_OS.com.company.BarTest.xml
sonar.sourceEncoding=UTF-8
below is my jsTestDriver.conf
server: http://localhost:9876
load:
- C:/Sonar/sonar-runner-dist-2.4/sonar-runner-2.4/projects/sources/*.js
- C:/Sonar/sonar-runner-dist-2.4/sonar-runner-2.4/projects/sources/com/company/*.js
test:
- C:/Sonar/sonar-runner-dist-2.4/sonar-runner-2.4/projects/tests/*.js
- C:/Sonar/sonar-runner-dist-2.4/sonar-runner-2.4/projects/tests/com/company/*.js
plugin:
- name: "coverage"
jar: "coverage-1.3.5.jar"
module: "com.google.jstestdriver.coverage.CoverageModule"
My sonarqube is running on port : 9000 and below is the screen shot. As you see SonarRunner and jsTestDriver just doing a code analysis and not showing any unit tests.
SonarQube doc website says jsTestDriver will run the javascript unit
tests and copy the results in target folder in XML format
SonarQube doesnt run your Unit Tests, it just gathers the reports generated from your manuall run or other tools automatic run (like: Jenkins).
From SonarQube doc:
Prior to the SonarQube analysis, execute your unit tests in order to
generate XML report. The JUnit like XML format supported is the one
generated by js-test-driver
Then I manually created report file in XML format as described, but
still no luck.
If you created manually the report files and reports are still not showing, check your paths if ok.Check if sonar is really reading data from C:/Sonar/sonar-runner-dist-2.4/sonar-runner-2.4/projects/ path

Unit Tests Coverage issue in sonar after upgrade to 4.2

We have recently upgraded sonar from 2.14 to sonar 4.2. This has an effect on the Unit Test coverage values. The Unit Test showed 100% with 0 errors but after the upgrade it now coming as 93.6% and 243 errors. If I see the details of the error, it shows the error message "A NullPointerException was thrown. This may indicate an error in your ActionForm, or it may indicate that the Struts ActionServlet was unable to find struts config file. TestCase is running from C:\Java\Jenkins\jobs\abc-quality\workspace\abc-WEB directory. Context directory is C:\Java\Jenkins\jobs\abc-quality\workspace\abc-WEB\WebContent. struts config file must be found under the context directory, the directory the test case is running from, or in the classpath.
servletunit.struts.ExceptionDuringTestError: A NullPointerException was thrown. This may indicate an error in your ActionForm, or it may indicate that the Struts ActionServlet was unable to find struts config file. TestCase is running from C:\Java\Jenkins\jobs\abc-quality\workspace\abc-WEB directory. Context directory is C:\Java\Jenkins\jobs\abc-quality\workspace\abc-WEB\WebContent. struts config file must be found under the context directory, the directory the test case is running from, or in the classpath."
We have not changed any configuration post upgrade so don't understand the reason of this error. This has further affected the code coverage percentage on sonar dashboard. How to resolve this error and get the unit test percentage as 100%. Also, I would like to add that I see the same issue when we upgrade to sonar 3.4.1 from 2.14. Any workaround for it?
We are using cobertura and not jacoco so would need help with cobertura end.
sonar properties being used are as below:
-Dsonar.login=sonar
-Dsonar.password=sonar
-Dsonar.dynamicAnalysis=reuseReports
-Dsonar.java.coveragePlugin=cobertura
-Dsonar.cobertura.reportPath=target/site/cobertura/coverage.xml

Resources