Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sonarcube using rspec not showing count of Unit Tests

I'm using Sonarqube with RoR and RSpec as testing tools, successfully get coverage but not the count of Unit Tests as shown on the image below:

Sonarqube report

Please help 🙏🏼


Configuration:

spec_helper.rb

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

sonar-project.properties

sonar.projectKey=myapp
sonar.sources=.
sonar.exclusions=**/vendor/**,**/coverage/**,**/assets/**
sonar.tests=app-code/spec
sonar.test.inclusions=**/*_spec.rb
sonar.test.exclusions=**/vendor/**
sonar.ruby.coverage.reportPaths=app-code/coverage/.resultset.json
sonar.ruby.coverage.framework=RSpec

Gemfile

  gem 'simplecov', '>= 0.17', '< 0.18'
  gem 'simplecov-json', '<= 0.2'
like image 404
Ardi Nusawan Avatar asked Jun 23 '20 10:06

Ardi Nusawan


People also ask

Is RSpec used for unit testing?

RSpec is a unit test framework for the Ruby programming language. RSpec is different than traditional xUnit frameworks like JUnit because RSpec is a Behavior driven development tool.

How do I get unit test coverage in SonarQube?

SonarQube supports the reporting of test coverage as part of the analysis of your Java project. However, SonarQube does not generate the coverage report itself. Instead, you must set up a third-party tool to produce the report as part of your build process.

Is SonarQube used for unit testing?

SonarQube offers reports on duplicated code, coding standards, unit tests, code coverage, code complexity, comments, bugs, and security recommendations.

What is RSpec testing?

RSpec is a testing tool for Ruby, created for behavior-driven development (BDD). It is the most frequently used testing library for Ruby in production applications. Even though it has a very rich and powerful DSL (domain-specific language), at its core it is a simple tool which you can start using rather quickly.


1 Answers

The simplecov is only used for coverage metrics. Unfortunately the is no native Ruby plugin that you can use to create a unit test count report, but you can use a sonar.testExecutionReportPaths parameter with generic report. I've used this formater for it.

sonar.testExecutionReportPaths=./path-to-your/report.xml 
like image 144
vAD271 Avatar answered Oct 28 '22 13:10

vAD271