Skip to main content

Search 436 pages — tools, formats, elements, namespaces, directory, comparisons, XPath, datatypes, glossary, parse errors, schema errors, use cases, guides, blog and product.

XML format

JaCoCo report

Java coverage as XML, with counters at every level — the format Sonar, Codecov and coverage gates in CI actually read.

JaCoCo's XML report is what a coverage gate reads. It nests package, class, sourcefile and method, and attaches <counter> elements at every level for instructions, branches, lines, complexity, methods and classes. Each counter carries missed and covered, so a percentage is a division you perform rather than a number the file states.

The counter that matters is rarely the one people quote. LINE coverage is the headline, but BRANCH is what catches an untested else, and a report with high line coverage and low branch coverage describes a suite that executes code without testing it.

Constraints that bite

  • Coverage is missed and covered counts, never a percentage. covered / (covered + missed) is the ratio, and the denominator can be zero.
  • Counters appear at several nesting levels and the outer ones are totals, not additional data — summing them across levels double-counts.
  • The report declares a DOCTYPE pointing at a JaCoCo DTD. Parsers that fetch external DTDs will try to reach the network; disable that.
  • A class with no executable lines is still listed, with zero counters. Treating that as 0% coverage skews the aggregate.
  • The XML report is not generated by default — the Maven and Gradle plugins have to be asked for it explicitly.
Root element
<report>
Media type
application/xml
Extensions
.xml
Namespaces
None — unqualified elements
XMLDir label

Specification: JaCoCo report formats

A minimal valid document

Every example on this site is checked against the same parser the workspace uses, so what you see below is known to be well-formed.

jacoco-report.xml
<?xml version="1.0" encoding="UTF-8"?>
<report name="example">
  <package name="com/example">
    <class name="com/example/Order" sourcefilename="Order.java">
      <method name="total" desc="()I" line="14">
        <counter type="INSTRUCTION" missed="0" covered="9"/>
        <counter type="BRANCH" missed="1" covered="1"/>
        <counter type="LINE" missed="0" covered="3"/>
      </method>
      <counter type="LINE" missed="0" covered="3"/>
    </class>
    <counter type="LINE" missed="0" covered="3"/>
  </package>
  <counter type="INSTRUCTION" missed="0" covered="9"/>
  <counter type="BRANCH" missed="1" covered="1"/>
  <counter type="LINE" missed="0" covered="3"/>
</report>

Get started

Bring order to the XML your team can't afford to ignore.

Create a free account and get a private workspace to search, validate, diff, and monitor your XML feeds, sitemaps, schemas, and vendor integrations.