I have a sample .Net Framework project that I would like to be able to see the coverage in SonarCloud using vstests. I have tried several combinations but I do not get the correct result.
Looking at the official documentation (.NET Test Coverage | SonarCloud Docs) I see that it is not necessary in the preparation of sonarcloud indicate the property or point to the generated coverage file, since it does it automatically if it is Windows-latest (but if I add sonar.cs.vscoveragexml.reportsPaths=“$(Agent.TempDirectory)\TestResults***.coveragexml” doesn’t work either) and you also have to add --collect “Code coverage”. I haven’t added the latter to my .yml file since I don’t know how to add it, but adding the Code Coverage enabled check I think is enough.
Also, in the SonarCloud Analyze log, it seems that it is taking coverage, but then in SonarCloud it appears 0.0%
INFO: Parsing the Visual Studio coverage XML report D:\a\_temp\TestResults\37670d3b-7516-4b7d-98e0-cc95fc087d75\VssAdministrator_fv-az290-59_2022-07-10.10_43_34.coveragexml
INFO: Adding this code coverage report to the cache for later reuse: D:\a\_temp\TestResults\37670d3b-7516-4b7d-98e0-cc95fc087d75\VssAdministrator_fv-az290-59_2022-07-10.10_43_34.coveragexml
What is happening to me?
This is my yml:
trigger:
- main
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller@1
- task: NuGetCommand@2
inputs:
restoreSolution: '$(solution)'
- task: SonarCloudPrepare@1
inputs:
SonarCloud: 'SonarCloud'
organization: 'example'
scannerMode: 'MSBuild'
projectKey: 'example'
projectName: 'example'
- task: VSBuild@1
inputs:
solution: '$(solution)'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: VSTest@2
inputs:
testSelector: 'testAssemblies'
testAssemblyVer2: 'HolaMundoTests/bin/Debug/netcoreapp3.1/HolaMundoTests.dll'
searchFolder: '$(System.DefaultWorkingDirectory)'
codeCoverageEnabled: true
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: SonarCloudAnalyze@1