Is there anyway to merge cobertura coverage xml reports together?

后端 未结 5 1829
时光说笑
时光说笑 2021-01-04 02:29

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 o

相关标签:
5条回答
  • 2021-01-04 03:11

    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.

    0 讨论(0)
  • 2021-01-04 03:11

    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)

    0 讨论(0)
  • 2021-01-04 03:15

    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

    0 讨论(0)
  • 2021-01-04 03:22

    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.

    0 讨论(0)
  • 2021-01-04 03:23

    It seems you're using gcovr. Since version 4.2, gcovr can merge its JSON reports with the -a option. So you could do:

    # run test1
    ./test1
    gcovr ... --xml coverage-test1.xml --json coverage-test1.json
    find . -type f -name '*.gcda' -exec rm {} +
    
    # run test2
    ./test2
    gcovr ... --xml coverage-test2.xml --json coverage-test2.json
    find . -type f -name '*.gcda' -exec rm {} +
    
    # combine JSON reports
    gcovr -a coverage-test1.json -a coverage-test2.json --xml coverage-combined.xml
    
    0 讨论(0)
提交回复
热议问题