Getting some insights from Jacoco html report

A simple script to count packages that contain classes with low coverage

Andres Canavesi
Nov 29, 2021
featured image


After running the Jacoco report generator we can open it and see the coverage results. There are some results the I wanted to know, for example, how many packages contain uncovered classes and how many contain coverage under a given threshold, in this case, I used 60%. So I build a script to count them and print in the browser's console. So, step into Jacoco's report tab and paste this script in your browser console to execute it and see the output


const table = document.getElementById("coveragetable");
const row = table.rows;
let uncoveredPackages = 0;
let columnFound = false; // the instructions coverage
let thresholdCoverage = 60;
let packagesUnderThreshold = 0;
let totalPackages = 0;
let i = 0;
while (!columnFound && i < row[0].cells.length) {
  // Getting the text of columnName
  const str = row[0].cells[i].innerHTML;
  if ("Cov.") != -1) {
    if (!columnFound) {
      // this is the first column with coverage for instructions the next "Cov." column is the one for branches
      columnFound = true;
      // iterate every row but the head and foot
      for (let j = 1; j < row.length - 1; j++) {
        const content = row[j].cells[i].innerHTML;
        const cov = parseFloat(content);
        if (cov === 0) {
        if (cov < thresholdCoverage) {
console.log(`total packages: ${totalPackages}`);
console.log(`uncovered packages: ${uncoveredPackages}`);
console.log(`packages under  ${thresholdCoverage}%: ${packagesUnderThreshold}`);



total packages: 226

uncovered packages: 60

packages under 60%: 157

Photo by Ryutaro Uozumi on Unsplash

jacoco java javascript dev