This Task converts .coverage file into .coveragexml to be used with Report Generator.
- I created this extension to help my pipeline process.
- Instead building a script which I would use only for me, I rather share the same code with everyone, so people don't need to waste their time searching for things that should be out of the box.
- Learning some new stuff like AzureDevOps Tasks and a bit of Node.
-
We can't use Coverage.exe to generate .coverage file
-
💔 We can't use VSTest@2 Task with codeCoverageEnabled as true
- If we enabled it, this will add a file into Code Coverage tab in Azure DevOps, which will override the Report Generator reports.
- This is not because Code Coverage, it is because VSTest@2 upload the coverage generated by itself to Azure Pipeline Tab Code Coverage automatically and we can't disable it. If they didn't upload the code coverage automatically we could use the coverage file generated by the VSTest@2. That is why the Code Coverage needs to execute again the VSTest@2.
- Here is Review Code Coverage Results Documentation from Microsoft.
- Here is a thread that I asked to update the documentation to make it clear.
- To be clear, we can use the VSTest@2 in our YML file, but we cannot use the Test Coverage from that task, the Code Coverage needs to be executed again, in order to get the coverage files.
Basically we need to add these tasks in Azure DevOps.
- Execute Code Coverage(CoverageConverter@0)
- This task will execute vsTest.exe which is the same used when we use VSTest@2 in azure DevOps.
- The result of vsTest.exe is the *.coverage files.
- The task will get all *.coverage file and covert into *.coveragexml, which is the format that Report Generator uses to generate a nice interface in Azure DevOps.
- Execute Report Generator(reportgenerator@4) to generate the Reports
- This task will get the .coveragexml that we generated and generate the reports into a folder.
- Execute Publish Code Coverage Results task(PublishCodeCoverageResults@1)
- This Task will get the Report and publish into Azure Code Coverage Tab.
Azure Pipeline YML File - Example 1
Take a look in the code, I tried to comment the code to make that easier to understand. It is all in one file.
https://github.com/Rogeriohsjr/AzureDevOpsTask/blob/master/buildAndReleaseTask/index.ts