-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not able to render Code Coverage results in the "Code Coverage" tab in Azure DevOps #13632
Comments
@pradudev Can you share the .runsettings file ? |
@pradudev I had the same thing. I had reached out to support for ADO but they weren't very helpful. I basically drove the full process and figured out the cause of this. The findingsI came to the conclusion that if the VsTest task uploads the test results, your custom report being uploaded is ignored. When the VsTest task is uploading the test report to ADO, the coverage is an attachment to that and automatically gets uploaded. Since the pipeline already has code coverage registered it doesn't accept anything else. Since ADO doesn't merge the coverage files it kind of makes sense but then you can only publish the coverage once in the whole pipeline. The workaround
|
P.S. Microsoft support said they won't do anything about it unless it gets community support on their developer communities. There was an idea raised some time ago to bring back the .coverage conversion directly in ADO: https://developercommunity.visualstudio.com/idea/366142/support-vstest-coverage-code-coverage-build-result.html |
I have tried a lot to solve his problem... So first of all, the problem is the test task of the pipeline (in my case the DotNetCoreCLI@2 task). If this task collects the code coverage it is automatically published with the tests in the .coverage format. For some reason this push of the .coverage file is at the end of the pipeline (or job - this I do not know) and therefore overrides all the previously uploaded files. The SolutionUse a Coverage Tool like OpenCover and collect the code coverage with that instead of the collection via the test task with CodeCoverage collection on. Example: Afterwards convert the OpenCover file via the ReportGenerator task into Cobertura format. And after that you can publish it as usual via the PublishCodeCoverageResult task. You might have to try arround a little but with that solution in mind it will work. |
Your issue is with Step 4. => "Run tests using above tool and generate .coverage file" If a .coverage file is created and left alone, Azure DevOps will pick it up and use it over anything else you create later. So basically your coverage.xml or any generated HTML report is ignored at the Code Coverage tab. So instead of using VSTest task and whatever you used beneath that, try adding a .Net Core Test to your pipeline and configure it to spit out "XPlat Code Coverage" using coverlet collector. Make sure NOT TO pass in any .runsettings file via --settings. Before doing any of that, you will need to add the NuGet coverlet.collector for all your test projects. Then add your task to publish the coverage results. You don't need the report generator, it's now built-in. That's all. Hopefully, you will be able to see the generated HTML getting rendered under Code Coverage tab. |
Thank you @elninoisback your guide was VERY helpful! Got my stuff to publish after following your example. |
There is another way to achieve this (the Full coverage on the "Code coverage" tab on the build), without using coverlet. Now thanks to microsoft/vstest#981 (comment)) is possible to use dotnet test with cobertura format:
You can also use This is good for the full coverage. For the diff coverage on the pull request instead, saddly you have to generate .coverage file. Actually I have two different pipelines (one for the full coverage as showed, the second for the diff coverage) |
Hi @pradudev, Powershell Task Inline command to convert to xml file
|
@Manikandanmani You can also use |
@fhnaseer , Thanks for the info I'll try that. |
@fhnaseer, I could able to convert into xml file, but this file is generated under userprofile, also I have an Invalid file issue when I downloaded the coverage file by using the below powershell script, but if I directly download the same coverage file from the codecoverage tab in the build, the convertion works. could you take a look on this. In this below picture,the coverage file downloaded are for the same build, not sure about the size difference.
|
@Manikandanmani You can also provide output path in command line [-o|--output ]. Regarding downloading with ps scritp, I am not sure about it. But it seems like 9746.coverage file is not valid. |
@nehsharmMS mentioned here that MS has new preview option to enable for Code Coverage, does it only require .coverage file? Then coverlet etc. would be not needed. |
@simonachmueller, are you meaning to say that the .coverage file generated in the pipelines would also provides individual coverage metrics for each file covered ?, btw is this can be achieved in vstest.console.exe [ships with visual studio] or using dotnet test cli? correct me if i am wrong here. |
@fhnaseer , I found out the reason why the downloaded file was corrupted ,because I forgot to add the authentication as headers when downloading the coverage file, after adding the headers downloads the coverage file without any issues Invoke-RestMethod -Uri $json.psobject.properties["value"].Value.codeCoverageFileUrl Get -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $AzureDevOpsAuthenicationHeader)} -OutFile $downloadedFile |
As I understood, there is a preview feature on Azure DevOps to use .coverage file to display code coverage in the build results without needing to generate html results separately. |
I never ear that. Is true? |
@gioce90 nope, unfortunately fake news from MS (seems like they tested it, but did not release). |
Is this issue resolved with the mentioned steps above ? |
@skotian2 is resolved only if you launch a task that use directly the cobertura format, as I described previously.
But as solution you can:
Returning to your question @skotian2 , if this issue is resolved, I see two possible answers:
|
To me, the real fix for this would be for Microsoft to update Azure DevOps so that you also get the diff PR integration if you use coverlet (not just .coverage). Then we could just use a single coverlet collector and get our reports displayed as well as get the benefit of the PR integration and coverage policies. If this was an option, I wouldn't have the need for multiple collectors. The fact that the .coverage file blocks the coverlet report from rendering is not good. But that wouldn't be an issue for me if I could just use coverlet. But I can't do that because I need the PR integration. If the PR integration worked for coverlet, we could also use non-Windows build agents which would be fantastic. I'd also be able to simplify a lot of my pipelines which are currently generating both coverage reports and publishing the coverlet report as a separate artifact that I have to download instead of having it render in the browser. |
I think exactly like you. My solution is just a workaround on a problem that only Microsoft can address. |
This issue is stale because it has been open for 180 days with no activity. Remove the stale label or comment on the issue otherwise this will be closed in 5 days |
I have a classic build pipeline in Azure DevOps for that builds and run tests for a .Net Core 3.1 app
I am using self-hosted build agents running Windows Server 2019 OS
Below is the pipeline screenshot
My tasks:
Build runs successfully
Publish Code Coverage task log
Build run summary
Published files by the build
Code Coverage tab
Issue: The code coverage tab does not display the HTML reports
The text was updated successfully, but these errors were encountered: