0

I have setup SonarCloud with my C# project, and it works fine, I can see Code Coverage and Unit Tests but these Unit Tests are only static number of my tests i.e. 13 when I entered into this I cannot see the tests structure instead No results. I checked logs from SonarCloud Analyze and it does not contain any errors. All my tests are in XUnit and all results are stored in XUnitResults.xml file that is provided via sonar.cs.xunit.reportsPaths=$(Build.SourcesDirectory)/**/XUnitResults.xml - this line consumes all XUnitResults.xml.

INFO: Sensor C# Tests Coverage Report Import [csharp] (done) | time=699ms
INFO: Sensor C# Unit Test Results Import [csharp]
INFO: Parsing the XUnit Test Results file 'D:\a\1\s\{MY_PROJECT_PATH}\XUnitResults.xml'.
INFO: Parsing the XUnit Test Results file 'D:\a\1\s\{MY_PROJECT_PATH}\XUnitResults.xml'.
INFO: Sensor C# Unit Test Results Import [csharp] (done) | time=41ms
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=1ms

Additionally for the coverage I do have a line sonar.cs.opencover.reportsPaths=$(Build.SourcesDirectory)/**/Coverage.opencover.xml which is also consumed fine.

INFO: Sensor C# [csharp] (done) | time=720ms
INFO: Sensor C# Tests Coverage Report Import [csharp]
INFO: Parsing the OpenCover report D:\a\1\s\TestResults\Coverage.opencover.xml
INFO: Adding this code coverage report to the cache for later reuse: D:\a\1\s\TestResults\Coverage.opencover.xml

I tried to use .trx and unfortunately it does not work as here, the only result was a static number of tests.

Reddi
  • 677
  • 6
  • 19
  • Could you please share the build definition with us? Are you using the tasks from [Sonar Cloud extension](https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarcloud)? – Kevin Lu-MSFT Mar 25 '21 at 07:31
  • @KevinLu-MSFT My solution is being build using `dontnetcorecli@2` tasks, and this task is also used to run all tests that produce the `XUnitResults.xml` file. This file is correct, as I checked this command using `dotnet test ` with the same args provided in the Azure DevOps and the output is as expected. As for `SonarCloud` I use 3 tasks, `SonarCloudPrepare`, `SonarCloudAnalyze` and `SonarCloudPublish` in the `SonarCloudPrepare` I've extra properties with these lines above. – Reddi Mar 25 '21 at 08:34
  • And the answer was? – Peter Marshall Jan 12 '22 at 11:49
  • There was no answer. – Reddi Jan 12 '22 at 12:04

0 Answers0