lundi 4 mars 2019

SonarQube not displaying test code coverage of Ruby on Rails project

I have a Ruby on Rails project that I want to display test coverage in SonarQube. The project is built with Jenkins which sends the results to SonarQube. Unit tests are run with rspec and code coverage is calculated with SimpleCov. SonarQube requires that code coverage report is generated in json format so I used simplecov-json in my rails_helper.rb:

if Rails.env.development? || Rails.env.test?
  require 'simplecov'
  require 'simplecov-json'
  SimpleCov.formatter = SimpleCov::Formatter::JSONFormatter
  SimpleCov.start
end

Code coverage report is generated successfully and saved to coverage folder like this (from Jenkins console output):

Coverage report generated for RSpec to /my-project/coverage/coverage.json. 2000 / 2000 LOC (100.0%) covered.

I configured my sonar-project.properties like this (to read the coverage report):

sonar.sources=.
sonar.exclusions=**/*_test.go,**/vendor/**,**/coverage/**

sonar.tests=.
sonar.test.inclusions=**/*_spec.rb
sonar.test.exclusions=**/vendor/**
sonar.ruby.coverage.reportPaths=coverage/coverage.json
sonar.ruby.coverage.framework=RSpec

Jenkins builds the project, runs the tests, generates the coverage report, sends the results to SonarQube. But SonarQube always displays 0% coverage for some reason.

enter image description here

Aucun commentaire:

Enregistrer un commentaire