Publish unit test results of python using sonar

Hi Team,

I was trying to publish a sonar scan report along with code coverage and Unit Tests, Its working fine in all the cases except Unit Tests.

  - task: SonarSource.sonarqube.15B84CA1-B62F-4A2A-A403-89B77A063157.SonarQubePrepare@5
    displayName: 'Prepare analysis on SonarQube'
    inputs:
      SonarQube: SonarQube
      scannerMode: CLI
      configMode: manual
      cliProjectKey: 'abcd-Server'
      cliProjectName: 'abcd-Server'
      cliSources: AWS/Lambdas
      extraProperties: |
          # Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
          # This property is optional if sonar.modules is set.
          sonar.c.file.suffixes=-
          sonar.cpp.file.suffixes=-
          sonar.objc.file.suffixes=-
          sonar.exclusions=**\_third_party_packages\**\*
          sonar.python.version=3.9
          sonar.python.xunit.skipDetails=true
          sonar.python.coverage.reportPaths=$(Build.SourcesDirectory)/AWS/Lambdas/coverage.xml
          sonar.python.xunit.reportPath=$(Build.SourcesDirectory)/AWS/Lambdas/.unittests/unittest-*.xml

In my case on the path $(Build.SourcesDirectory)/AWS/Lambdas/.unittests there are multiple files are generated after running the test cases like unittest-abc.xml, unittest-xyz.xml etc.

when I am providing a single file along with the path I am able to see the test cases but not for multiple files.
Could anyone please help me with this?

Hi,

I don’t think the substitution is happening like you expect it to. The sonar.python.coverage.reportPaths parameter accepts a comma-delimited list of paths, so your best bet is to explicitly list each report.

 
HTH,
Ann

Hi, @ganncamp Thanks for the quick reply.

I am having the issue with sonar.python.xunit.reportPath to show all test cases, in my case, there are multiple xml files that I want to show on the sonar dashboard.

I am using the below line of code for this and it’s not working.

sonar.python.xunit.reportPath=$(Build.SourcesDirectory)/AWS/Lambdas/.unittests/unittest-*.xml