How to Publish Code Coverage results for Multiple Cobertura.xml file in TFS 2017 Build? - code-coverage

I am using TFS 2017 Update3 and I have a Build definition which runs Grunt build task at two different HTML projects and generates two cobertura.xml files at their respective paths.
To display the code coverage result I have used Publish Code Coverage Results task in my build pipeline but it displays the Code coverage for only 1 project and doesn't display the code coverage result of other Html Project.
I tried using two Publish Code Coverage Results task each pointing to different cobertura.xml files but still it displays the code coverage result for only one project on TFS build summary.
Is there any other ways by which I can publish multiple code coverage result?

Related

How to get Publish Test Results task also publish .cobertura file produced by VsTest Task

Publish Test Results task mentions that "You can also use this task in a build pipeline to publish code coverage results produced when running tests to Azure Pipelines or TFS in order to obtain coverage reporting."
However, I have tried this for my test report of type .cobertura format. And it doesn't create the coverage tab. Though it works for .coverage and .covx/.covb files (tested)
<DataCollector friendlyName="Code Coverage">
<Configuration>
<Format>Cobertura</Format>
</Configuration>
</DataCollector>
I'm using VSTPI 17.1 to get cobertura support from VS 2022 however my ADO is using VS 2019.
So is it actually supported? If yes then what's required to make it work?
Alternatively, I can use PublishCodeCoverageResults task, however
I miss the power of VsTest task followed by publish-test-results task's auto aggregating results from multiple jobs within the same build or will not? https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/test/publish-code-coverage-results doesn't specify it however with publish-test-results, I always see aggregated results (desired)
And the doc mentions
"
Tasks such as Visual Studio Test, .NET Core also provide the option to publish code coverage data to the pipeline. If you are using these tasks, you do not need a separate Publish Code Coverage Results task in the pipeline."
And also there is a limit of 7 KB for this task.
Hence "Publish Test Results" should publish cobertura type as well because it's supported by the VsTest
Else I would run into needing to self merge multiple of them https://github.com/microsoft/vstest/issues/3497#issuecomment-1084741316
Expected: Publish Test Results Task to also publish the coverage to Coverage tab from .cobertura files.

TFS Publish Code Coverage Results Task With OpenCover not working

Running Build on TFS 2015 On Permises and my code coverage result Task logs warning saying that coverage data not found. But the xml file was read during the build process.
I have configured the Publish Code Coverage Results like described in the picture:
The logs during build are saying that the file was produced and it was read.
and at the end of all files it says this:
I was expecting to see some code coverage resume data on the build, but that was not the case:
Thanks #DanielMann that reminder helped. Im using openCover and i was not understanding that OpenCover had is own format. Now I change my Cake script to support conversion from openCover to Cobertura.
I added the headers in the cake script like this:
#addin "nuget:?package=Cake.OpenCoverToCoberturaConverter&version=0.1.1.2"
#tool "nuget:?package=OpenCoverToCoberturaConverter&version=0.3.2"
and then after tests executed with sucess I run my code coverage like this:
OpenCover(tool => {
tool.XUnit2($"{testsPath}/**/**/**/**/{projectName}.dll",xUnit2Settings);
}, new FilePath("./OpenCoverCoverageResults.xml"),openCoverSettings);
OpenCoverToCoberturaConverter("OpenCoverCoverageResults.xml", "CoberturaCoverageResults.xml");
ReportGenerator($"CoberturaCoverageResults.xml", $"{outputDir}/Reports");

How to display the Code coverage result using Index.html on VSTS\TFS 2017 Build Summary?

I have a build definition that runs grunt build and generates code coverage results using cobertura tool in cobertura.xml files. The cobertura.xml is used in Publish code coverage result task to publish code coverage result on VSTS build summary.
Along with cobertura.xml file, I have one Index.html file present in same folder which also contains code coverage result in detail. I want to call Index.html file using publish code coverage result task to display code coverage result on build summary instead of cobertura.xml.
I tried doing that by passing the name of index.html along with its path in the publish task but it fails.
Is there any way by which I can display the code coverage using index.html?

TFS 2013 does not publish .coverage file on server

I'm developing a quality workflow with TFS 2013 and SonarQube 4.5.1. Everything works fine except one thing: I can't integrate code coverage data from TFS to SonarQube. The problem is that SonarQube needs .trx or .cover files to work.
However, my TFS Build doesn't publish those files. What I've done: I created a CodeCoverage.runsettings file that I mapped on my build with "User defined" type. (With CodeCoverageEnabled it doesn't work either.) In the file CodeCoverage.runsettings, I wrote the following XML tag:
<RunConfiguration>
<ResultsDirectory>.\TestResults</ResultsDirectory>
</RunConfiguration>
in the hope that it would write all the results files in the same directory. The build does indeed create the results directories, but none of them contain .coverage files. However, at the end of the build, in the results page, I can download a .coverage file. Do you know how I can force the writing of this .coverage file on the server? When I run analysis on my local config, the file is created in the test results directory.

Generate two coverage reports in a single jenkins build

I have a Jenkins build which build all my java/angularJS project. It launch testNG tests for the java part and karma tests for the javascript part. So I can generate one testNG report (for java) and one junit report (for karma test) in my Jenkins build. This is working very well.
Until now, I used cobertura to report the coverage of my java tests. But now I would like to add also a coverage report for my karma tests (generated by Istanbul with cobertura type). The problem is that, in Jenkins, I'm allowed to generate only one coverage report in a build (I can't add more that one 'publish cobertura coverage report' post build action). So how can I have these two coverage reports in a single Jenkins build?
There's a nice plugin called HTML Publisher Plugin. You can generate HTML coverage reports and publish as much reports as you want under different titles in one Jenkins project.
For example I generate html reports using karma+istanbul and then publish them to Jenkins.
On JUnit xml report files. You should import JUnit once enumerating all files probably from different directories but you can differentiate them with proper package names inside files.
If I'm right, you can't use, as a post build action, the same plug-in twice( note that I'm not really sure). I faced this problem when I worked as Jenkins plug-in developer for a company and the solution was to use a plug-in that make the same thing.
For example: for JUnit reports there is an official JUnit plugin and also XUnit. For my problem it was simple.
So, maybe you can find a plug-in that do the same thing as Cobertura or you can change the output format of the java coverage or karma coverage. For example, for java you can use EclEmma or Jacoco...

Resources