Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sonarqube ignore test execution data

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!

like image 494
Greg Avatar asked Feb 14 '18 09:02

Greg


2 Answers

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".

like image 144
Brian Mahecha Avatar answered Nov 04 '22 00:11

Brian Mahecha


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.

like image 34
Danna Avatar answered Nov 04 '22 00:11

Danna