Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to interpret the jacoco.xml file?

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

like image 251
Chathura Wijeweera Avatar asked Nov 23 '15 10:11

Chathura Wijeweera


People also ask

How do you analyze a JaCoCo report?

In IntelliJ Idea from the menu select Analyze > Show Coverage data . In the new window press the + button and select your . exec file. The test coverage results will appear in the editor Coverage tab.

What is JaCoCo XML report?

JaCoCo reports are an essential component of Cover Reports, which provides insights about your code to help your team identify gaps in your application's coverage.

How do I get my JaCoCo code coverage report?

To get code coverage reports in a Maven project, we first need to set up the JaCoCo Maven plugin for that project. By integrating the JaCoCo plugin, the results of the code coverage analysis can be reviewed as an HTML report. The current version of the JaCoCo-Maven plugin can be downloaded from the MVN Repository.

How does JaCoCo code work?

Jacoco is an open source project, which can be used to check production code for test code coverage. It creates reports and integrates well with IDEs like the Eclipse IDE. Integration is also available for other IDEs and continuous integration environments.


1 Answers

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

like image 179
Steve Peak Avatar answered Oct 08 '22 18:10

Steve Peak