We have several C# repositories which are built via Azure DevOps Yml pipelines.
Until recently we have been getting code coverage across all of our repositories.
However, now in one repository we get code coverage for branches but NOT pull requests (even though both use the same pipelines), and in other repositories we get no coverage at all, even though the SonarCloud and testing configurations are identical apart from obvious settings such as SonarCloud project etc. When I say no coverage, the SonarCloud page says that coverage is not set up for that particular project.
Our SonarCloud configuration looks like this:
- task: SonarCloudPrepare@2
displayName: 'SonarCloud Prepare'
inputs:
SonarCloud: 'SonarCloud'
organization: 'xxx'
scannerMode: 'xxx'
projectKey: 'xxx'
projectName: 'xxx'
We then use a VSBuild
step to build the code, and a DotNetCoreCLI@2
step to build the software and execute the tests. The arguments we use to produce code coverage are:
arguments: '--configuration $(BuildConfiguration) --collect "Code Coverage" --logger trx'
We then publish the results and execute the SonarCloud analysis and publish:
- task: PublishTestResults@2
displayName: 'Publish Test Results'
inputs:
testResultsFormat: 'VSTest'
testResultsFiles: '/**/*.trx'
- task: SonarCloudAnalyze@2
displayName: Run Sonar Analysis
- task: SonarCloudPublish@2
displayName: Publish Sonar Results
inputs:
pollingTimeoutSec: '300'
Once the build has finished, we get a coverage report as part of the pipeline build, and I am able to pull down the coverage files and open them, so I don’t understand why SonarCloud essentially doesn’t see that there is any code coverage at all.
Also, just to reiterate, we have the above implementation for several repositories, but one of the repositories at least reports coverage for branches.