Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The SonarQube system analyzes source code for problems and reports the results, including test code-coverage statistics, to https://www.sonarcloud.io. The analyses are usually run weekly by a Jenkins job.  This section summarizes the project configuration that is required. Analyzing and reporting static source-code features requires almost no configuration, basically just naming the directory with source code. Reporting code-coverage statistics requires that the project's build and test steps generate those statistics, which requires automated unit tests that can be run by Jenkins.  This section focuses on test configuration to generate coverage data suitable for consumption by the Sonar scanner. See the section later in this document on Jenkins job configuration for details about that.

Configure

...

Golang Project for Code Coverage

Go projects should use the go-acc tool (``go get -v github.com/ory/go-acc``) to run tests and generate the file coverage.txt.  This yields better results than standard features in golang versions 1.12 and 1.13.  Here's an example:

   go-acc $(go list ./... | grep -vE '(/tests|/enums)' )

However modules are not supported yet by the Sonar Scanner. If you rewrite the module name in the coverage report to the name of the directory with source code, Sonar will match the coverage data with its source analysis.  Also see: https://jira.sonarsource.com/browse/SONARSLANG-450

Configure

...

Java Project for Code Coverage

Java projects should use the jacoco maven plugin in their POM file, which instruments their code and gathers code-coverage statistics during JUnit tests. Here's an example:

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.4</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>

Configure a Python Project for Code Coverage

Python projects should extend the tox.ini file that runs tests as follows.

First, add required packages within the  `[testenv]` block:

deps=
pytest
coverage
pytest-cov

Second, add the following commands within the `[testenv]` block:

commands =
pytest --cov dir-name --cov-report xml --cov-report term-missing --cov-report html --cov-fail-under=70
coverage xml -i

Setting up development environment

Eclipse users can see Sonar results in an especially convenient way.

Making Java code checked by Sonar

To make Java code checked by Sonar locally an addition to the projects pom file is needed, see below.

...