How to disable code coverage in sonarqube since 6.2
Asked Answered
T

2

12

Since we updated to SonarQube 6.2 it seems code coverage plugin got merged in the core. It shows red flags everywhere and I can’t find how to turn it off, we do not use code coverage.

Tamaru answered 22/2, 2017 at 10:48 Comment(0)
C
21

You don't specify what language(s) you're analyzing. I'll assume Java and/or JavaScript. Starting from 6.2, SonarQube supports "force coverage to 0", which marks as uncovered executable lines in files that don't show up in any coverage reports. (That's assuming the underlying code analyzers support the feature, and Java and JavaScript already do.) The purpose is to have a more accurate picture of what's missing when you actually are using unit tests. Without this feature, it's impossible to tell whether a file that's omitted from coverage reports is missing because it has no executable code or because there are no tests on it - even when there should be.

Since you're not using unit tests (really?) you can exclude all the source files in your project from coverage calculations via the UI: Administration > Analysis Scope > Coverage Exclusions. A pattern value of **/*.* ought to do it for you.

Correspond answered 22/2, 2017 at 20:27 Comment(7)
Hello, sorry it’s for PHP I did not think it changed anything. I tried adding . but it does not seem to help, my files still have red bars on the left side. We have tests, just not coverage.Rank
You did run an analysis after changing the settings, right?Correspond
is it possible to force zero coverage in the sonnar-scanner cmd? e.g. sonnar-scanner -Dforce.zero.coverage=true or sth like that?Hymenopterous
That is a new and different question @HymenopterousCorrespond
There should be way to disable code coverage, as unit tests aren't the only kind of test automation code. I work with TestComplete UI scripts written in JavaScript. While I want to see the quality of those scripts, it doesn't make sense to write unit tests for them.Selfimmolating
In Version 7.9.1 you find it here: Administration > General Settings > Analysis Scope > Coverage ExclusionsNock
The last sentence of the answer worked best for me. I added the following to my properties file. That changed the coverage metric in the web UI from "0.0%" to "-". sonar.coverage.exclusions=**/*.*"Dissension
U
2

Code coverage feature is in SonarQube misleading. To turn this off:

  1. Under Quality gates create new or copy existing profile.
  2. There delete Coverage metric

SonarQube Version: 9.2

Ut answered 2/5, 2022 at 9:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.