Number of unit tests is zero

Hi,

Analysis of our code base all looks good except the number of unit tests are blank. Screenshot attached. The code and tests are a mixture of kotlin and java.

I have set the following on the gradle command line

-Dsonar.junit.reportPaths=**/build/test-results/**/*.xml

  • SQ Version 8.3.1 (build 34397), Jenkins Jenkins 2.231

Is this due to https://jira.sonarsource.com/browse/SONARSLANG-353?

Many thanks,
Richard

Hello @rm25282,

If you have Java code then the Junit report should be read, at least partially (I don’t know how the report looks when the it is on a mix of Java and Kotlin code).
I rather suspect that you have the problem because you’re using wildcards in your property. For historical reasons some report properties support wildcards, some don’t - And the documentation on sonar.junit.reportPaths does not mention wildcard support.

You should have a quite clear log in your scanner execution that would explain why the unit test report is not imported (either wildcard not supported it the files will not be found, or potentially error parsing the junit report if the java plugin does not like that there is some kotlin stuff in there).
Send me the scanner logs (preferable in DEBUG mode) if you want me to take a look.

Olivier

Hi @OlivierK,
i am using Jest, JUnit with sonarQube… in my SonarQube i am not able to see unit tests, below is my sonar properties and log.
Please suggest me on this.

[Test/Sonar] INFO: Parsing /reports/test-reporter.xml
[Test/Sonar] INFO: ------------------------------------------------------------------------
[Test/Sonar] INFO: EXECUTION FAILURE
[Test/Sonar] INFO: ------------------------------------------------------------------------
[Test/Sonar] INFO: Total time: 23.444s
[Test/Sonar] INFO: Final Memory: 31M/117M
[Test/Sonar] INFO: ------------------------------------------------------------------------
[Test/Sonar] ERROR: Error during SonarQube Scanner execution
[Test/Sonar] ERROR: Error during parsing of generic test execution report ‘/reports/test-reporter.xml’. Look at the SonarQube documentation to know the expected XML format.
[Test/Sonar] ERROR: Caused by: Line 3 of report refers to a file which is not configured as a test file: /src/ test /Users.spec.js
[Test/Sonar] ERROR:
[Test/Sonar] ERROR: Re-run SonarQube Scanner using the -X switch to enable full debug logging.
[Pipeline] [Test/Sonar] }
[Test/Sonar] WARN: Unable to locate ‘report-task.txt’ in the workspace. Did the SonarScanner succeeded?

sonar.sources=./src
sonar.tests=./src/__test__

sonar.test.inclusions=./src/__test__/*.spec.js
sonar.coverage.exclusions=./src/__test__/__snapshots__/**
sonar.exclusions=./src/assets/*,./node_modules/*,./src/__test__/*

sonar.javascript.junit.reportPaths=./junit.xml
sonar.javascript.lcov.reportPaths=./output/coverage/jest/lcov.info
sonar.testExecutionReportPaths=./reports/test-reporter.xml

Thanks Olivier for the reply and apologies for taking so long to get back to you.

Indeed I am seeing this in my analysis

Reports path not found or is not a directory: /home/ubuntu/workspace/new_product_develop/exporter//build/test-results//*.xml

I will try again with a hardcoded path.

Does this mean I have to list every directory to scan?

Hello Richard,

The requirement to list all files is not the same for every language and every test tool. Depending on the language and the tool the unit tests and coverage data is produced differently and we had to adjust. So I cannot give you a response if you don’t tell me what language and what coverage tool we’re talking about.
I see in your properties that you try to set sonar.javascript.junit.reportPaths. This property does not exist. We support junit for Java only. For Javascript you have to use the generic test report format we propose as explained in the doc link below.

Please have a look at the details of all the properties at https://docs.sonarqube.org/latest/analysis/coverage/#header-2

Olivier

Hi Olivier,

Sorry but it looks like someone has posted their question in here too. Our env is a mixture of Kotlin and Java code and unit tests. From what you are saying and the documentation will only the Java ones show up in SonarQube? So can you confirm I need to add this

-Dsonar.junit.reportPaths=project_dir1/build/test-results, project_dir2/build/test-results

and keep adding for every directory that has unit tests in it?

Many thanks,
Richard

Hello Richard,

Junit tests results anyhow relates to number of tests executed, passed, failed and skipped, without limited notion on the code (or language) they were run on. So you only get to totals numbers, nothing more. They will aggregate the Java and Kotlin tests I would assume (although I never tried this configuration I must say)

About your second question, the path is supposed to be relative to the module root directory (if you have a modular Maven project for instance), so if the files have the same name and path relative to the module home, a simple -Dsonar.junit.reportPaths=build/test-results should be enough.
I would need to know more of your project structure to be sure that this simple configuration would work. Worth a try though…

Olivier

Hi Richard,

are there any positive results in using a concrete path instead of having wildcards in it?

We have a similar project structure (Android/Kotlin/Gradle) and also have the same problem of missing any test result (nether a test counter nor a test chapter within coverage) even if pass a concrete path for sonar.junit.reportPaths (without wildcards).

Regarding the original topic. Previously surefire reports on Kotlin tests were not supported. In the latest version of Kotlin plugin this feature was added and will be available with the next SonarQube release.

Regards,
Margarita