currently we have our builds on running on Azure DevOps on Windows agents and everything works.
We tried now to port it to a Linux (Ubuntu) agents. Unfortunately the build doesn’t calculate code coverage one the Ubuntu machine. It constantly stays empty and therefore the build breaks on every attempt.
I tried several combinations of different yaml files and googled a lot but couldn’t resolve the issue. My current yaml looks like this.
thanks for the hint. The file is not generated as far as I see. I tried a few different configurations last week but none of them seem to work and generate the coverage. Do you have maybe a demo configuration for .net core 3.1 on Linux agents? Is there something wrong with the parameters that I am using?
I was wondering if that may work since your are using coverlet, but as far as i know, coverage is still not supported on linux agent, see this thread : https://github.com/Microsoft/vstest/issues/981
Thanks @mickaelcaro. I was skimming through the github thread and it seems to be an ongoing issue. Is there any alternative way instead of coverlet to get it working with Sonarcloud on a Linux agent?
This was actually a push in the right direction. Now I am not getting any more warnings from the tasks. I switched to opencover but still experience the same issue. I was following the second tutorial that you posted and filled the gaps with this one:https://writeabout.net/2019/04/27/net-core-code-coverage-done-right/
Now I see in Azure Devops, the correct coverage calculated but it is not propagated to Sonar.
When you run the SonarCloudAnalyze task, in debug mode, do you see some kind of debug log around the coverage processing ? It should tell you how many files it discovered and so on… Would be probably helping you troubleshoot.
Sorry, I forgot to append the logs in the last reply. I am not sure what I am looking for in the logs.
I noticed just that opencover is just mentioned twice in the upper section of the log so I am not sure if Sonar picks it up.
Remove coverlet output from .net test task so the file is stored in the same directory as the project file
Change the report generator task -reports parameter "-reports:$(Build.SourcesDirectory)/**/coverage.opencover.xml" to search in all directories
Run .net test on the .sln file instead of single project files
This helped me to fix it. Now coverage is generated and uploaded the Sonarcloud. I also added attributes so that the ExcludeFromCodeCoverage attribute is taken into account.
There is just one thing I noticed that is weird. The coverage with open cover is about 5 percent lower when running on the windows agent. Event though the report shows the same line coverage. Do you have any idea on top of your mind?
Well i don’t know, do you have the possibility to open both coverage files in Visual Studio to see where the coverage is missing ? So then you’ll have a clue.
Good advice, some of the test projects were included in the windows build definition so now it will be even more accurate Thanks once more @mickaelcaro you really helped me a lot!