How to skip unit tests analysis but display their number?

Must-share information:

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
    SonarQube 9.9 CE
    jacoco 0.8.8
    jdk jdk17
    mvn 3.9

  • what am I trying to achieve?
    I’d like to show number of unit-tests on the UI, but skip SonarQube analysis of those tests. Coverage is shown correctly, while unit-tests number is not.

  • what have you tried so far to achieve this
    mvn clean verify sonar:sonar -Dsonar.host.url=*** -Dsonar.language=java -Dsonar.login=*** -Dsonar.scm-provider=git -Dsonar.verbose=true -Dsonar.scm.forceReloadAll=true -Dsonar.profile=*** -Dsonar.projectName=*** -Dsonar.projectKey=*** -Dsonar.java.codeCoveragePlugin=jacoco -DskipTests=false

I also have this exclusion setting: sonar.global.test.exclusions=src/test/**

image

[2023-04-17T09:48:50.404Z] [INFO] User cache: /root/.sonar/cache
[2023-04-17T09:48:51.341Z] [INFO] SonarQube version: 9.9.0.65466
[2023-04-17T09:48:51.341Z] [INFO] Default locale: "en_US", source code encoding: "UTF-8"
[2023-04-17T09:48:52.716Z] [INFO] Load global settings
[2023-04-17T09:48:52.716Z] [INFO] Load global settings (done) | time=146ms
[2023-04-17T09:48:52.716Z] [INFO] Server id: ***
[2023-04-17T09:48:52.716Z] [INFO] User cache: ***
[2023-04-17T09:48:52.716Z] [INFO] Load/download plugins
[2023-04-17T09:48:52.716Z] [INFO] Load plugins index
[2023-04-17T09:48:52.716Z] [INFO] Load plugins index (done) | time=93ms
[2023-04-17T09:48:55.995Z] [INFO] Load/download plugins (done) | time=3042ms
[2023-04-17T09:48:56.930Z] [INFO] Process project properties
[2023-04-17T09:48:56.930Z] [INFO] Process project properties (done) | time=18ms
[2023-04-17T09:48:56.930Z] [INFO] Execute project builders
[2023-04-17T09:48:56.930Z] [INFO] Execute project builders (done) | time=2ms
[2023-04-17T09:48:56.930Z] [INFO] Project key: ***
[2023-04-17T09:48:56.930Z] [INFO] Base dir: ***
[2023-04-17T09:48:56.930Z] [INFO] Working dir: ***
[2023-04-17T09:48:56.930Z] [INFO] Load project settings for component key: '***'
[2023-04-17T09:48:57.188Z] [INFO] Load quality profiles
[2023-04-17T09:48:57.188Z] [INFO] Load quality profiles (done) | time=83ms
[2023-04-17T09:48:57.447Z] [INFO] Load active rules
[2023-04-17T09:48:58.822Z] [INFO] Load active rules (done) | time=1256ms
[2023-04-17T09:48:58.822Z] [INFO] Load analysis cache
[2023-04-17T09:48:58.822Z] [INFO] Load analysis cache (404) | time=4ms
[2023-04-17T09:48:58.822Z] [WARNING] Use of sonar.test.exclusions and sonar.tests.exclusions at the same time. sonar.test.exclusions is taken into account. Consider updating your configuration
[2023-04-17T09:48:58.822Z] [INFO] Load project repositories
[2023-04-17T09:48:58.822Z] [INFO] Load project repositories (done) | time=6ms
[2023-04-17T09:48:58.822Z] [INFO] Indexing files...
[2023-04-17T09:48:58.822Z] [INFO] Project configuration:
[2023-04-17T09:48:58.822Z] [INFO]   Excluded tests: src/test/**
[2023-04-17T09:48:59.081Z] [WARNING] Use of sonar.test.exclusions and sonar.tests.exclusions at the same time. sonar.test.exclusions is taken into account. Consider updating your configuration
[2023-04-17T09:48:59.653Z] [INFO] *** files indexed
[2023-04-17T09:48:59.653Z] [INFO] *** files ignored because of inclusion/exclusion patterns
[2023-04-17T09:48:59.653Z] [INFO] 0 files ignored because of scm ignore settings
[2023-04-17T09:48:59.653Z] [INFO] Quality profile for java: ***
[2023-04-17T09:48:59.653Z] [INFO] Quality profile for xml: ***
[2023-04-17T09:48:59.653Z] [INFO] ------------- Run sensors on module ***
[2023-04-17T09:48:59.910Z] [INFO] Load metrics repository
[2023-04-17T09:48:59.910Z] [INFO] Load metrics repository (done) | time=44ms
[2023-04-17T09:49:03.220Z] [INFO] Sensor JavaSensor [java]
[2023-04-17T09:49:03.220Z] [INFO] Configured Java source version (sonar.java.source): 11
[2023-04-17T09:49:03.220Z] [INFO] JavaClasspath initialization
[2023-04-17T09:49:03.220Z] [INFO] JavaClasspath initialization (done) | time=16ms
[2023-04-17T09:49:03.220Z] [INFO] JavaTestClasspath initialization
[2023-04-17T09:49:03.220Z] [INFO] JavaTestClasspath initialization (done) | time=13ms
[2023-04-17T09:49:03.220Z] [INFO] Server-side caching is enabled. The Java analyzer will not try to leverage data from a previous analysis.
[2023-04-17T09:49:03.220Z] [INFO] Using ECJ batch to parse 231 Main java source files with batch size 500 KB.
[2023-04-17T09:49:03.480Z] [INFO] Starting batch processing.
[2023-04-17T09:49:04.862Z] [INFO] The Java analyzer cannot skip unchanged files in this context. A full analysis is performed for all files.
[2023-04-17T09:49:14.858Z] [INFO] 77% analyzed
[2023-04-17T09:49:19.054Z] [INFO] 100% analyzed
[2023-04-17T09:49:19.054Z] [INFO] Batch processing: Done.
[2023-04-17T09:49:19.054Z] [INFO] Did not optimize analysis for any files, performed a full analysis for all 231 files.
[2023-04-17T09:49:19.054Z] [WARNING] Unresolved imports/types have been detected during analysis. Enable DEBUG mode to see them.
[2023-04-17T09:49:19.054Z] [WARNING] Use of preview features have been detected during analysis. Enable DEBUG mode to see them.
[2023-04-17T09:49:19.054Z] [INFO] No "Test" source files to scan.
[2023-04-17T09:49:19.054Z] [INFO] No "Generated" source files to scan.
[2023-04-17T09:49:19.054Z] [INFO] Sensor JavaSensor [java] (done) | time=15626ms
[2023-04-17T09:49:19.054Z] [INFO] Sensor JaCoCo XML Report Importer [jacoco]
[2023-04-17T09:49:19.054Z] [INFO] Importing 1 report(s). Turn your logs in debug mode in order to see the exhaustive list.
[2023-04-17T09:49:19.054Z] [INFO] Sensor JaCoCo XML Report Importer [jacoco] (done) | time=293ms
[2023-04-17T09:49:19.054Z] [INFO] Sensor CSS Rules [javascript]
[2023-04-17T09:49:19.054Z] [INFO] No CSS, PHP, HTML or VueJS files are found in the project. CSS analysis is skipped.
[2023-04-17T09:49:19.054Z] [INFO] Sensor CSS Rules [javascript] (done) | time=25ms
[2023-04-17T09:49:19.054Z] [INFO] Sensor C# Project Type Information [csharp]
[2023-04-17T09:49:19.054Z] [INFO] Sensor C# Project Type Information [csharp] (done) | time=3ms
[2023-04-17T09:49:19.054Z] [INFO] Sensor C# Analysis Log [csharp]
[2023-04-17T09:49:19.054Z] [INFO] Sensor C# Analysis Log [csharp] (done) | time=70ms
[2023-04-17T09:49:19.054Z] [INFO] Sensor C# Properties [csharp]
[2023-04-17T09:49:19.054Z] [INFO] Sensor C# Properties [csharp] (done) | time=1ms
[2023-04-17T09:49:19.054Z] [INFO] Sensor FindBugs Sensor [findbugs]
[2023-04-17T09:49:19.054Z] [INFO] Findbugs plugin version: 4.2.3
[2023-04-17T09:49:22.348Z] [INFO] Loading findbugs plugin: ***
[2023-04-17T09:49:22.348Z] [INFO] Findbugs output report: ***
[2023-04-17T09:50:09.034Z] The following classes needed for analysis were missing:
[2023-04-17T09:50:09.034Z]   makeConcatWithConstants
[2023-04-17T09:50:09.034Z]   apply
[2023-04-17T09:50:09.034Z]   test
[2023-04-17T09:50:09.034Z]   accept
[2023-04-17T09:50:09.034Z]   get
[2023-04-17T09:50:09.034Z]   compare
[2023-04-17T09:50:09.034Z]   customize
[2023-04-17T09:50:09.034Z]   run
[2023-04-17T09:50:09.034Z]   extractThrows
[2023-04-17T09:50:09.034Z]   call
[2023-04-17T09:50:09.034Z]   execute
[2023-04-17T09:50:09.034Z]   health
[2023-04-17T09:50:09.034Z]   answer
[2023-04-17T09:50:09.034Z] [INFO] Sensor FindBugs Sensor [findbugs] (done) | time=46077ms
[2023-04-17T09:50:09.034Z] [INFO] Sensor SurefireSensor [java]
[2023-04-17T09:50:09.034Z] [INFO] parsing ***
[2023-04-17T09:50:09.034Z] [INFO] Sensor SurefireSensor [java] (done) | time=333ms
[2023-04-17T09:50:09.034Z] [INFO] Sensor HTML [web]
[2023-04-17T09:50:09.034Z] [INFO] Sensor HTML [web] (done) | time=14ms
[2023-04-17T09:50:09.034Z] [INFO] Sensor XML Sensor [xml]
[2023-04-17T09:50:09.034Z] [INFO] 1 source file to be analyzed
[2023-04-17T09:50:09.034Z] [INFO] 1/1 source file has been analyzed
[2023-04-17T09:50:09.034Z] [INFO] Sensor XML Sensor [xml] (done) | time=440ms
[2023-04-17T09:50:09.034Z] [INFO] Sensor TextAndSecretsSensor [text]
[2023-04-17T09:50:09.034Z] [INFO] 232 source files to be analyzed
[2023-04-17T09:50:09.034Z] [INFO] 232/232 source files have been analyzed
[2023-04-17T09:50:09.034Z] [INFO] Sensor TextAndSecretsSensor [text] (done) | time=301ms
[2023-04-17T09:50:09.034Z] [INFO] Sensor VB.NET Project Type Information [vbnet]
[2023-04-17T09:50:09.034Z] [INFO] Sensor VB.NET Project Type Information [vbnet] (done) | time=2ms
[2023-04-17T09:50:09.034Z] [INFO] Sensor VB.NET Analysis Log [vbnet]
[2023-04-17T09:50:09.034Z] [INFO] Sensor VB.NET Analysis Log [vbnet] (done) | time=27ms
[2023-04-17T09:50:09.034Z] [INFO] Sensor VB.NET Properties [vbnet]
[2023-04-17T09:50:09.034Z] [INFO] Sensor VB.NET Properties [vbnet] (done) | time=1ms
[2023-04-17T09:50:09.034Z] [INFO] Sensor IaC Docker Sensor [iac]
[2023-04-17T09:50:09.034Z] [INFO] 0 source files to be analyzed
[2023-04-17T09:50:09.034Z] [INFO] 0/0 source files have been analyzed
[2023-04-17T09:50:09.034Z] [INFO] Sensor IaC Docker Sensor [iac] (done) | time=122ms
[2023-04-17T09:50:09.034Z] [INFO] ------------- Run sensors on project
[2023-04-17T09:50:09.034Z] [INFO] Sensor Analysis Warnings import [csharp]
[2023-04-17T09:50:09.034Z] [INFO] Sensor Analysis Warnings import [csharp] (done) | time=2ms
[2023-04-17T09:50:09.034Z] [INFO] Sensor Zero Coverage Sensor
[2023-04-17T09:50:09.034Z] [INFO] Sensor Zero Coverage Sensor (done) | time=24ms
[2023-04-17T09:50:09.034Z] [INFO] Sensor Java CPD Block Indexer
[2023-04-17T09:50:09.034Z] [INFO] Sensor Java CPD Block Indexer (done) | time=330ms
[2023-04-17T09:50:09.034Z] [WARNING] Forced reloading of SCM data for all files.
[2023-04-17T09:50:09.034Z] [INFO] SCM Publisher SCM provider for this project is: git
[2023-04-17T09:50:09.034Z] [INFO] SCM Publisher *** source files to be analyzed
[2023-04-17T09:50:09.034Z] [INFO] SCM Publisher ***/*** source files have been analyzed (done) | time=***ms
[2023-04-17T09:50:09.034Z] [WARNING] Missing blame information for the following files:
[2023-04-17T09:50:09.034Z] [WARNING]   * pom.xml
[2023-04-17T09:50:09.034Z] [WARNING] This may lead to missing/broken features in SonarQube
[2023-04-17T09:50:09.034Z] [INFO] CPD Executor 108 files had no CPD blocks
[2023-04-17T09:50:09.034Z] [INFO] CPD Executor Calculating CPD for *** files
[2023-04-17T09:50:09.034Z] [INFO] CPD Executor CPD calculation finished (done) | time=70ms
[2023-04-17T09:50:09.034Z] [INFO] Analysis report generated in ***ms, dir size=***
[2023-04-17T09:50:09.971Z] [INFO] Analysis report compressed in ***ms, zip size=***
[2023-04-17T09:50:09.971Z] [INFO] Analysis report generated in ***
[2023-04-17T09:50:10.907Z] [INFO] Analysis report uploaded in ***ms
[2023-04-17T09:50:10.907Z] [INFO] ANALYSIS SUCCESSFUL, you can find the results at: ***
[2023-04-17T09:50:10.907Z] [INFO] Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
[2023-04-17T09:50:10.907Z] [INFO] More about the report processing at ***
[2023-04-17T09:50:10.907Z] [INFO] Analysis total time: *** s
[2023-04-17T09:50:10.907Z] [INFO] ------------------------------------------------------------------------
[2023-04-17T09:50:10.907Z] [INFO] BUILD SUCCESS
[2023-04-17T09:50:10.907Z] [INFO] ------------------------------------------------------------------------
[2023-04-17T09:50:10.907Z] [INFO] Total time:  *** min
[2023-04-17T09:50:10.907Z] [INFO] Finished at: ***
[2023-04-17T09:50:10.907Z] [INFO] ------------------------------------------------------------------------

Hi,

You’ve got a lot of parameters on your command line, but not the one you need. To get statistics about the tests themselves, you’ll need to pass in a test execution report.

Regarding your other parameters:

This does nothing

This is read from your file system. If it can’t be read from your file system, the presence of this parameter will cause analysis to error-out.

This is not for everyday use. It’s for the rare occasion when you need to reset all the SCM data for your project. Having it there unnecessarily will significantly increase your analysis duration.

This does nothing

Unless you’re overriding the values in your pom, these are unnecessary in a Maven analysis

This does nothing.

 
HTH,
Ann

Hi
Thank You for your reply.
I cleaned up the code and added the flag -Dsonar.junit.reportPaths=target/surefire-reports.
Indeed the surefire-reports directory exists there and contains files.
However, even though the SonarQube recognizes the flag and parses it, as I can see in the logs:

[2023-05-30T07:02:35.610Z] [INFO] Sensor SurefireSensor [java]
[2023-05-30T07:02:35.610Z] [INFO] parsing [/var/lib/jenkins/workspace/MyApp_master/target/surefire-reports]
[2023-05-30T07:02:35.610Z] [INFO] Sensor SurefireSensor [java] (done) | time=158ms

There is still no UT count visible on the scan page.
Any idea why this could happen?
Thanks in advance
Best regards

Hi,

Try bumping the analysis log level up with either -Dsonar.log.level=DEBUG or -Dsonar.verbose=true on the analysis command line, and let’s see what details we get.

 
Ann