Is there anyway to merge cobertura coverage xml reports together?

有些话、适合烂在心里 提交于 2019-11-30 03:06:45

问题


I have c++/c application with a lots of unit tests. I would like to get overall coverage and also individual coverage of each test with condition that each test can be run only once. Format of coverage must be xml (cobertura xml) for jenkins cobertura plugin to process.

So far I generate gcno files upon compilation and gcda files when source is used. Then call gcovr to get xml file.

I would like to create coverage of each unit test (thus creating coverage xml for every unit test) and then merge these xml files into one xml file.

Thanks!


回答1:


The last release of ReportGenerator can merge cobertura files.

You can install it from nuget

usage:

reportgenerator "-reports:target\*\*.xml" "-targetdir:C:\report" -reporttypes:Cobertura

A file Corbertura.xml is generated in the targetdir directory

You can use the dotnet core version to use it on linux or mac




回答2:


Sorry can't comment:

@x3mspeedy was nice enough to post a script, but they have moved the script around a bit since then, I searched the repo and pulled it into a public gist here:

https://gist.github.com/tgsoverly/ef975d5b430fbce1eb33




回答3:


I wrote python script which can merge cobertura reports together. It only merges line "hits" and is able to filter specific packages while merging.

Conditional(branch-rate) coverage and line coverage (line-rate) percentage values are not merged yet. Jenkins plugin recalculates these values so in this context it doesn't have to be implemented (but maybe it will).

Also conditional coverage can't seem to be put together easily, so it doesn't work when reports cooperate on final value (meaning one file has condition-coverage 50% (2/4) and other also condition-coverage 50% (2/4) other two branches. Result is set to be higher of these two numbers so it will be still 50% (2/4)




回答4:


For what it's worth, I made a node script to merge multiple cobertura XML reports. Set up is quite straightforward and it fits my needs. https://gist.github.com/merlosy/8efabc754985aa6e754a3d5932b1a77d




回答5:


The simplest utility I've found for merging Cobertura files is cobertura-merge via NPM.

Usage:

npm install cobertura-merge
cobertura -merge -o output.xml package1=input1.xml package2=input2.xml

Or it can be used directly without installing through npx:

npx cobertura-merge -o output.xml package1=input1.xml package2=input2.xml

Examples sourced from the GitHub README for cobertura-merge.




回答6:


Cannot add comments so see :

https://github.com/cobertura/cobertura/wiki/Command-Line-Reference

on the bottom.




回答7:


I was looking at solution as well, but in my case there was about 1000 of Cobertura XML files and all above scripts were really slow in processing such amount.

In the end I've come up with merge-cobertura.py a Python script which does the merge. However it's quite limited in what it supports as all I needed was to merge reports from OpenCppCoverage to be used at Codecov. So it just merges line hits ignoring any branch information (there is none coming from OpenCppCoverage) and assuming all coverage reports are for same path. It also merges all packages into one.

Maybe somebody will find this useful as well, there are some more details in my blog.



来源:https://stackoverflow.com/questions/26469072/is-there-anyway-to-merge-cobertura-coverage-xml-reports-together

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!