16

I am using the JACOCO tool in Maven project. It creates code coverage XML file "jacoco.xml". As I'm going to parse this xml I need to know the meaning of some attributes in the xml file. xml contains following elements:

    <sourcefile name="Ops.java">
        <line nr="3" mi="0" ci="3" mb="0" cb="0"/>
        <line nr="5" mi="0" ci="4" mb="0" cb="0"/>
        <line nr="11" mi="0" ci="5" mb="2" cb="2"/>
        <line nr="12" mi="0" ci="2" mb="0" cb="0"/>
        <line nr="14" mi="8" ci="0" mb="0" cb="0"/>
        <line nr="15" mi="2" ci="0" mb="0" cb="0"/>
        <counter type="INSTRUCTION" missed="10" covered="14"/>
        <counter type="BRANCH" missed="2" covered="2"/>
        <counter type="LINE" missed="2" covered="4"/>
        <counter type="COMPLEXITY" missed="2" covered="3"/>
        <counter type="METHOD" missed="0" covered="3"/>
        <counter type="CLASS" missed="0" covered="1"/>
    </sourcefile>

variable "nr" seems to mean line number. what are the meanings of the variables "mi", "ci", "mb" and "cb"?

And here is the code coverage shown in generated html output.

generated html output

Chathura Wijeweera
  • 289
  • 1
  • 2
  • 9

1 Answers1

23

mi = missed instructions (statements) ci = covered instructions (statements) mb = missed branches cb = covered branches

  • When mb or cb is greater then 0 the line is a branch.
  • When mb and cb are 0 the line is a statement.
  • cb / (mb+cb) (line 11) is 2/4 partial hit (hence yellow)
  • When not a branch and mi == 0 the line is hit (hence green in line 5)

Thank you!

Bonus: Upload these reports to Codecov https://github.com/codecov/example-java

Steve Peak
  • 2,657
  • 1
  • 17
  • 18
  • 3
    You could get all the definitions in report.xml from [report.dtd](https://www.jacoco.org/jacoco/trunk/coverage/report.dtd). – Xiao May 16 '19 at 11:09