Sonarqube ignore test execution data
Asked Answered
M

2

9

I'm trying to import generic test execution with sonar.testExecutionReportPaths. I'm using the xml file format provided in the doc. I use full path to the file in the path attribute. And files exist.

I don't understand why my files are ignored. Any idea ?

sonar.testExecutionReportPaths = "C:\Program Files (x86)\Jenkins\workspace\CI\Sonarqube.xml"
sonar.test.inclusions = "**\*Test*.cs"

Here is the log from Sonar Runner:

INFO: Sensor Generic Test Executions Report
INFO: Parsing C:\Program Files (x86)\Jenkins\workspace\CI\Sonarqube.xml
WARNING: WARN: Property 'sonar.genericcoverage.unitTestReportPaths' is deprecated. Please use 'sonar.testExecutionReportPaths' instead.
INFO: Imported test execution data for 0 files
INFO: Test execution data ignored for 5 unknown files, including:
C:\Program Files (x86)\Jenkins\workspace\CI\Tests\A-Test.cs
C:\Program Files (x86)\Jenkins\workspace\CI\Tests\B-Tests.cs
C:\Program Files (x86)\Jenkins\workspace\CI\Tests\C-Tests.cs
C:\Program Files (x86)\Jenkins\workspace\CI\Tests\D-Test.cs
C:\Program Files (x86)\Jenkins\workspace\CI\Tests\E-Test.cs
INFO: Sensor Generic Test Executions Report (done) | time=265ms

Here is the a part of the Generic XMl File:

<testExecutions version="1">
  <file path="C:\Program Files (x86)\Jenkins\workspace\CI\Tests\A-Test.cs">
    <testCase name="My A Test" duration="1210" />
  </file>
  <file path="C:\Program Files (x86)\Jenkins\workspace\CI\Tests\B-Tests.cs">
    <testCase name="My B Test" duration="566" />
  </file>
</testExecutions>

Thank you!

Modish answered 14/2, 2018 at 9:57 Comment(3)
When you look at A-Test.cs in the SonarQube UI, how does the path displayed for it compare with the path in your report?Permute
It does not appear. I don't know if it's related to sonar.test.inclusions=***Test*.cs. I don't want thoses files to be included on metrics.Modish
It probably does not work, because the path in the file element does not match the file known to SonarQube.Unwarrantable
I
10

What did it for me was adding: sonar.testExecutionReportPaths=coverage/test-report.xml sonar.tests=src sonar.test.inclusions=**/*.spec.ts to my sonar-project.properties file. "sonarqube-scanner-node".

Imperium answered 27/9, 2018 at 12:26 Comment(0)
K
1

Basically, you need to confirm those parts if you want to make the sonar unit test count show correctly, it must be one of the error

  • Add config sonar.testExecutionReportPaths=xx/test-report.xml to properties and make sure the path is correct.
  • Check your test-report.xml file field and path content(file path="C:\Program Files (x86)\Jenkins\workspace\CI\Tests\A-Test.cs"), make sure the path is the same as the file in your local or server, for example, if you run this inside docker, you need to check the A-Test.cs file path in the docker container, whether it's the with the defined path in xml file.

Finally, I solved my problem by doing this check, hopefully, it can help you. And there are some tips from standard documentation here

* The root node should be named testExecutions.
* Its version attribute should be set to 1.
* Insert a file element for each test file. 
* Its path attribute can be either absolute or relative to the root of the module.

BTW, there is a warning in your sonar log:

WARNING: WARN: Property 'sonar.genericcoverage.unitTestReportPaths' is deprecated. Please use 'sonar.testExecutionReportPaths' instead.

But I can see you already use the testExecutionReportPaths, you may need to check whether sonar run the lasted version of settings and the option soanr56x is false in your package.json config.

Keyes answered 18/5, 2020 at 9:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.