#Scoverage Plugin for Sonar#
Plugin for SonarQube that imports statement coverage generated by Scoverage for Scala projects.
Scoverage measures how many statements of a given Scala program have been covered by automated tests. This new metric is much better for Scala than traditional line coverage and branch coverage because typically:
- There are many statements on a single line
if
statements are used rarely
This plugin reads XML report generated by Scoverage and populates several metrics in Sonar:
- Total number of statements
- Number of statements covered by tests
- Statement coverage rate (%)
Projects with sub-projects are supported as well. Overall statement coverage is (sum of number of covered statements for all sub-projects) / (total number of statements for all sub-projects). In other words, it's more intelligent than just plain average of coverage rates for sub-projects.
- [SonarQube 4.5] (https://github.com/RadoBuransky/sonar-scoverage-plugin/tree/sonar45)
- [SonarQube 4.2] (https://github.com/RadoBuransky/sonar-scoverage-plugin/tree/sonar42)
- [SonarQube 3.5] (https://github.com/RadoBuransky/sonar-scoverage-plugin/tree/sonar35)
Download and copy the plugin jar to the Sonar plugins directory (usually <SONAR_INSTALLATION_ROOT>/extensions/plugins). Restart Sonar.
Set location of the scoverage.xml file in the sonar-project.properties located in your project's root directory:
...
sonar.scoverage.reportPath=target/scala-2.11/scoverage-report/scoverage.xml
...
If your project is based on SBT and you're using [Scoverage plugin for SBT] sbt-scoverage you can generate the Scoverage report by executing following from command line:
$ sbt clean coverage test
And then run Sonar runner to upload the report to the Sonar server:
$ sonar-runner
To see the actual statement coverage percentage you need to log in to Sonar as admin. Click Components section on the left side, then click Customize ON in the top-right corner and then add Statement coverage column.
You can also add Statement coverage widget to your project's dashboard. Log in to Sonar as admin. Go to the project dashboard, click Configure widgets in the top-right corner, click Add widget button in the Custom Measures section. Click Edit in the newly added Custom Measures widget and choose Statement coverage for Metric 1. Click Save, Back to dashboard. Enjoy.
Take a look at a sample SBT multi-module project located in this repository in the samples
folder.
Project dashboard with Scoverage plugin:
Multi-module project overview:
Columns with statement coverage, total number of statements and number of covered statements:
Source code markup with covered and uncovered lines:
- Fixed issue #31
Michael Zinsmaier pull requests:
- Improved path handling, reported filenames are converted to src dir relative paths
- Adding directory coverage thus supporting the Treemap widget
- Added total statements metric to avoid overlaps with coremetrics
Justin Kaeser pull request:
- Upgrade to SonarQube 5.1 API
- Upgrade to SonarQube 4.2 API