0

SonarQube 版本:6.0.0 SonarJS:2.17.0.3154

问题

主要目的是在 SonarQube 仪表板中显示覆盖率报告和单元测试结果。虽然我能够获得覆盖率报告,但无法在 SonarQube 仪表板中获得单元测试结果。我一直在使用 mocha 进行单元测试,使用 istanbul nyc 进行代码覆盖。mocha 使用包 mocha-sonar-reporter 生成的报告是 xml 格式,覆盖率报告是 lcov 格式。

声纳仪表板

Sonar.Property 文件

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 日志

_[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_
4

1 回答 1

1

在这里回答https://github.com/SonarSource/sonar-javascript/issues/751

SonarJS 不再提供单元测试结果导入。为此,您应该使用 SQ 的原生功能Generic Test Data(自 SQ 6.2 起)。如果您使用 SQ < 6.2,请使用此插件https://docs.sonarqube.org/display/PLUG/Generic+Test+Coverage

于 2017-09-20T07:11:05.227 回答