0
0
JUnittesting~20 mins

JaCoCo setup and configuration in JUnit - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
JaCoCo Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Understanding JaCoCo Execution Data

What does the JaCoCo agent collect during test execution?

AThe total runtime of each test method
BInformation about which lines of code were executed during tests
CThe number of assertions in each test case
DThe memory usage of the JVM during tests
Attempts:
2 left
💡 Hint

JaCoCo focuses on code coverage, not performance metrics.

Predict Output
intermediate
2:00remaining
JaCoCo Maven Plugin Configuration Output

Given this Maven plugin snippet for JaCoCo, what is the expected output after running mvn test?

JUnit
<plugin>
  <groupId>org.jacoco</groupId>
  <artifactId>jacoco-maven-plugin</artifactId>
  <version>0.8.8</version>
  <executions>
    <execution>
      <goals>
        <goal>prepare-agent</goal>
      </goals>
    </execution>
    <execution>
      <id>report</id>
      <phase>test</phase>
      <goals>
        <goal>report</goal>
      </goals>
    </execution>
  </executions>
</plugin>
ANo coverage report is generated because the report goal is not bound to a phase
BTests fail because the plugin version is incompatible
CA coverage report is generated in target/site/jacoco/index.html after tests run
DThe build skips tests due to missing configuration
Attempts:
2 left
💡 Hint

Check the plugin executions and phases.

assertion
advanced
2:30remaining
Validating JaCoCo Coverage Thresholds in Gradle

Which Gradle configuration snippet correctly fails the build if line coverage is below 80%?

JUnit
jacocoTestCoverageVerification {
    violationRules {
        rule {
            limit {
                minimum = 0.80
            }
        }
    }
}
A
jacocoTestCoverageVerification {
  violationRules {
    rule {
      limit {
        counter = 'LINE'
        value = 'COVERED_RATIO'
        minimum = 0.80
      }
    }
  }
}
B
jacocoTestCoverageVerification {
  violationRules {
    rule {
      limit {
        counter = 'BRANCH'
        value = 'MISSED_COUNT'
        maximum = 0.20
      }
    }
  }
}
C
jacocoTestCoverageVerification {
  violationRules {
    rule {
      limit {
        counter = 'LINE'
        value = 'COVERED_COUNT'
        minimum = 80
      }
    }
  }
}
D
jacocoTestCoverageVerification {
  violationRules {
    rule {
      limit {
        counter = 'LINE'
        value = 'COVERED_RATIO'
        maximum = 0.80
      }
    }
  }
}
Attempts:
2 left
💡 Hint

Look for the correct counter, value, and minimum threshold.

🔧 Debug
advanced
2:00remaining
Troubleshooting Missing Coverage Data

After running tests with JaCoCo agent enabled, the coverage report shows 0% coverage. What is the most likely cause?

AThe source code is not compiled before running tests
BThe tests did not contain any assertions
CThe JaCoCo plugin version is outdated
DThe JaCoCo agent was not attached to the JVM during test execution
Attempts:
2 left
💡 Hint

Think about how JaCoCo collects coverage data.

framework
expert
3:00remaining
Integrating JaCoCo with CI Pipeline

In a CI pipeline using Jenkins, which step is essential to ensure JaCoCo coverage reports are archived and visible after the build?

AAdd a post-build action to archive the <code>target/site/jacoco</code> directory and publish HTML reports
BRun tests with <code>mvn clean install</code> only, no additional steps needed
CConfigure Jenkins to run JaCoCo as a separate job after tests complete
DDisable JaCoCo during CI to speed up builds
Attempts:
2 left
💡 Hint

Think about how Jenkins handles build artifacts and reports.