# FAQs

## Frequently Asked Questions (FAQs)

### Why do the Diffblue metrics not exactly match up with SonarQube’s Coverage metrics?

There can be slight discrepancies between SonarQube’s measures and the Diffblue SonarQube metrics. This is due to differences in how SonarQube, JaCoCo, and the Diffblue SonarQube Plugin define the following terms.

<table><thead><tr><th width="152.15234375"></th><th width="286.0390625">SonarQube</th><th>Diffblue SonarQube Plugin</th></tr></thead><tbody><tr><td>Coverable lines</td><td><p>Lines to cover. This is the number of lines of code that could be covered by unit tests. For example, blank lines or full comments lines are not considered as lines to cover.</p><p><br>If SonarQube's <code>xmlReportPaths</code> property is configured to use Diffblue's JaCoCo XML reports, this number will match the Diffblue SonarQube Plugin's <strong>Coverable Lines</strong> measure. If the property is not set or is set to other reports, there may be a slight difference.</p></td><td>A line is counted as coverable if, for a <code>line</code> in a <code>class</code> in the JaCoCo coverage reports, <code>ci + mi > 0</code> . That is, if the line contains at least 1 bytecode instruction.</td></tr><tr><td>Coverage</td><td><p>Mixes line and condition coverage. </p><p></p><p>See <a href="https://docs.sonarsource.com/sonarqube-server/user-guide/code-metrics/metrics-definition#coverage">https://docs.sonarsource.com/sonarqube-server/user-guide/code-metrics/metrics-definition#coverage</a> for the equation used.</p></td><td><p>Line coverage.</p><p></p><p>coverage = lines where at least one instruction is covered / coverable lines</p><p></p><p>This is based on JaCoCo’s documentation: <a href="https://www.eclemma.org/jacoco/trunk/doc/counters.html">https://www.eclemma.org/jacoco/trunk/doc/counters.html</a></p></td></tr><tr><td>Line coverage</td><td><p>Has this line of code been executed during the execution of the unit tests? </p><p><br>See <a href="https://docs.sonarsource.com/sonarqube-server/user-guide/code-metrics/metrics-definition#coverage">https://docs.sonarsource.com/sonarqube-server/user-guide/code-metrics/metrics-definition#coverage</a> for the equation used.</p></td><td>The Diffblue SonarQube Plugin doesn't distinguish between coverage and line coverage. Our measure of coverage is line-based as described above.</td></tr></tbody></table>

Generated code is another potential source of discrepancies between metrics. It is best practice to exclude generated code from coverage analysis. Diffblue Cover will warn if it detects that coverage was measured for generated code; see [Environment Codes - E165](/features/output-codes/e-environment-codes.md#e165-coverage-measured-for-generated-code) for how to configure JaCoCo to exclude generated code. See SonarQube's documentation for how to exclude generated code from SonarQube analysis.

### How does coverage highlighting work when using the Diffblue SonarQube Plugin?

While SonarQube will perform static analysis to determine Lines to Cover in the absence of coverage files, SonarQube's coverage highlighting in the UI will only work if coverage files are provided. If it cannot find coverage files, all lines will be shown as uncovered. Diffblue Cover's `coverage-reports` command writes files to specific location which differs from the standard location.&#x20;

To align SonarQube's coverage highlighting in the UI and the Lines to Cover measure with Diffblue's measures, configure your project to use the Diffblue-generated JaCoCo XML files using SonarQube's `sonar.coverage.jacoco.xmlReportPaths` property. The line coverage highlighting will then reflect lines covered by all Diffblue and manual tests. This can be done in several ways.

#### Set in the SonarQube UI

Go to **Project Settings** **>** **General Settings**. In the **JaCoCo** section, add an entry for each report: `.diffblue/reports/diffblue-tests-jacoco-report.xml` and `.diffblue/reports/manual-tests-jacoco-report.xml` . The order does not matter. These patterns will be used for each module in the project.

#### Within your project

The property can be set in your Maven or Gradle build files. For example, in a Maven project, you can set the below in the parent `pom.xml` , or in each module's `pom.xml` :

```
<properties>
    <sonar.coverage.jacoco.xmlReportPaths>
        .diffblue/reports/diffblue-tests-jacoco-report.xml,
        .diffblue/reports/manual-tests-jacoco-report.xml
    </sonar.coverage.jacoco.xmlReportPaths>
</properties>
```

In a Gradle project, add the below to the `build.gradle` :

```
sonarqube {
    properties {
        property "sonar.coverage.jacoco.xmlReportPaths",
                ".diffblue/reports/diffblue-tests-jacoco-report.xml," +
                ".diffblue/reports/manual-tests-jacoco-report.xml"
    }
}
```

#### Passed in the SonarQube CI command

For a Maven or Gradle project, add the below property to the SonarQube command run in CI:

```
-Dsonar.coverage.jacoco.xmlReportPaths='.diffblue/reports/diffblue-tests-jacoco-report.xml,.diffblue/reports/manual-tests-jacoco-report.xml'
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://cover-docs-preview.diffblue.com/features/diffblue-sonarqube-plugin/faqs.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
