Template for a good new topic, formatted with Markdown:
ALM used - Azure DevOps
CI system used - Azure DevOps (Ubuntu agent)
Scanner - MsBuild
Languages of the repository - C# NetCore 5.0 w/ xunit
Error observed - no coverage being reported back to SC
I have been struggling to get SC to report on code coverage for a new project I am setting up. It was understanding that this should work out of the box, I did follow the tutorial when I first setup the project in SC - adding of keys etc. All other metrics are working as expected.
I have followed a number of blog posts in an attempt to get this working but have had no success and now feel like im going around in circles.
Below are a couple of the more recnt posts that I have follwed but failed.
The key to making an AzDo pipeline be able to report coverage into sonar is going to be making sure that the test results and coverage files are being generated by the test task, and that those files are being found by the sonar Run Code Analysis task.
The sonar Run Code Analysis task does not have any configuration options that let you tell it where to look for the test results and coverage files, so it will have to be either the test task or a copy files task that places them where the sonar task can get them.
If you enable diagnostic logging and queue a build for a properly working pipeline, when its finished, in the Run Code Analysis task you should see a section that looks like near the beginning this where its finding the test result files.
Attempting to locate a test results (.trx) file...
Looking for TRX files in: D:\a\1\TestResults
No test results files found
Did not find any binary coverage files in the expected location.
Falling back on locating coverage files in the agent temp directory.
Searching for coverage files in D:\a\_temp
All matching files: count=2
Unique coverage files: count=1
Usually when no coverage is reported in sonar its because this section in the log indicates that no files were found after looking through the usual search paths. If thats what you see, then open the log for the Test task and see where it put the test result files. If it made the test results and coverage files, compare those paths with where the Sonar task is looking for them. Chances are that they are being put into a location where Sonar is not inspecting for.
Its been my experience that the dotnet test task looks like it should let you specify the result file path in the command arguments but that value is overrridden when the pipline executes. So if you want to keep this task you will need to add a copy task to copy the test result files to one of the places where Sonar is looking for them. If you dont want to have another task added to the pipeline, you can replace the dotnet test task with a visual studio test task that has a working config parameter. For either, just make sure you use the pipeline variable when possible, like ($(Agent.TempDirectory)\TestResults)