Unit test result does not show on SonarQube Dashboard for nodejs

3.5k views Asked by At

SonarQube Version : 6.0.0 SonarJS : 2.17.0.3154

Issue

The main aim is to display coverage report and the unit test result in SonarQube dashboard. Though I am able to get the coverage report but not able to get the unit test result in SonarQube dashboard . I have been using the mocha for unit testing and istanbul nyc for code coverage. The report generated by mocha is in xml format using the package mocha-sonar-reporter and the coverage report is in lcov format .

sonarqube dashboard

Sonar.Property File

sonar.projectKey=unittest
sonar.projectName=unittest 
sonar.projectVersion=1.0.0
sonar.sources=src/
sonar.tests=test/
sonar.language=js
sonar.sourceEncoding=UTF-8
sonar.javascript.jstestdriver.reportsPath=/home/jenkinsbot/workspace/devops_stuffs/reports
sonar.javascript.lcov.reportPath=/home/jenkinsbot/workspace/devops_stuffs/reports/lcov.info

SonarQube log :

_[Pipeline] wrap
Injecting SonarQube environment variables using the configuration: Sonar(dk.147)
[Pipeline] {
[Pipeline] sh
[e_feature_COS-239-unit-test-P23YKERWYLNSD6K3ISKUHA5NSJTRN6K7DRJGKI5QLG6LTD3HHOPA] Running shell script

/home/jenkinsbot/sonar-scanner-2.9.0.670/bin/sonar-scanner
INFO: Scanner configuration file: /home/jenkinsbot/sonar-scanner-2.9.0.670/conf/sonar-scanner.properties
INFO: Project root configuration file: /home/jenkinsbot/workspace//sonar-project.properties
INFO: SonarQube Scanner 2.9.0.670
INFO: Java 1.8.0_131 Oracle Corporation (64-bit)
INFO: Linux 4.4.0-92-generic amd64
INFO: User cache: /home/jenkinsbot/.sonar/cache
INFO: Load global repositories
INFO: Load global repositories (done) | time=94ms
INFO: User cache: /home/jenkinsbot/.sonar/cache
INFO: Load plugins index
INFO: Load plugins index (done) | time=4ms
INFO: SonarQube server 6.0
INFO: Default locale: "en_US", source code encoding: "UTF-8"
INFO: Process project properties
INFO: Load project repositories
INFO: Load project repositories (done) | time=100ms
INFO: Load quality profiles
INFO: Load quality profiles (done) | time=17ms
INFO: Load active rules
INFO: Load active rules (done) | time=231ms
INFO: Publish mode
INFO: ------------- Scan cosmicunittest
INFO: Language is forced to js
INFO: Load server rules
INFO: Load server rules (done) | time=71ms
INFO: Base dir: /home/jenkinsbot/workspace/
INFO: Working dir: /home/jenkinsbot/workspace/eP23YKERWYLNSD6K3ISKUHA5NSJTRN6K7DRJGKI5QLG6LTD3HHOPA/.scannerwork
INFO: Source paths: src
INFO: Test paths: test
INFO: Source encoding: UTF-8, default locale: en_US
INFO: Index files
INFO: 152 files indexed
INFO: Quality profile for js: LogPoint Way
INFO: Sensor Lines Sensor
INFO: Sensor Lines Sensor (done) | time=33ms
INFO: Sensor SCM Sensor
INFO: Sensor SCM Sensor (done) | time=20ms
INFO: Sensor JavaScript Squid Sensor
INFO: 138 source files to be analyzed
INFO: Unit Test Coverage Sensor is started
INFO: 138/138 source files have been analyzed
INFO: Analysing [/home/jenkinsbot/workspace/reports/lcov.info]
INFO: Integration Test Coverage Sensor is started
INFO: Overall Coverage Sensor is started
INFO: Analysing [/home/jenkinsbot/workspace/reports/lcov.info]
INFO: Sensor JavaScript Squid Sensor (done) | time=4852ms
INFO: Sensor XmlFileSensor
INFO: Sensor XmlFileSensor (done) | time=1ms
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=76ms
INFO: Sensor Code Colorizer Sensor
INFO: Sensor Code Colorizer Sensor (done) | time=3ms
INFO: Sensor CPD Block Indexer
INFO: DefaultCpdBlockIndexer is used for js
INFO: Sensor CPD Block Indexer (done) | time=1ms
INFO: Calculating CPD for 129 files
INFO: CPD calculation finished
INFO: Analysis report generated in 222ms, dir size=903 KB
INFO: Analysis reports compressed in 300ms, zip size=512 KB
INFO: Analysis report uploaded in 24ms
INFO: ANALYSIS SUCCESSFUL, you can browse http://test/dashboard/index/unittest
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
INFO: More about the report processing at test
INFO: Task total time: 7.649 s
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 8.784s
INFO: Final Memory: 61M/551M
INFO: ------------------------------------------------------------------------
[Pipeline] }
[Pipeline] // wrap
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // stage
[Pipeline] End of Pipeline
Finished: SUCCESS_
1

There are 1 answers

2
Elena Vilchik On

Answered here https://github.com/SonarSource/sonar-javascript/issues/751

Unit test results import is not provided anymore by SonarJS. For that you should use SQ's native feature Generic Test Data (since SQ 6.2). If you use SQ < 6.2 use this plugin https://docs.sonarqube.org/display/PLUG/Generic+Test+Coverage.