Bird
Raised Fist0
JUnittesting~20 mins

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

Choose your learning style10 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.

Practice

(1/5)
1. What is the primary purpose of JaCoCo in a JUnit testing environment?
easy
A. To replace JUnit as a testing framework
B. To run JUnit tests faster
C. To generate test data automatically
D. To measure how much of your code is tested by your unit tests

Solution

  1. Step 1: Understand JaCoCo's role

    JaCoCo is a code coverage tool that tracks which parts of your code are executed during tests.
  2. Step 2: Compare options

    Only To measure how much of your code is tested by your unit tests correctly describes JaCoCo's purpose; others describe unrelated functions.
  3. Final Answer:

    To measure how much of your code is tested by your unit tests -> Option D
  4. Quick Check:

    JaCoCo = Code coverage tool [OK]
Hint: JaCoCo measures tested code coverage, not test speed [OK]
Common Mistakes:
  • Confusing JaCoCo with test runners
  • Thinking JaCoCo generates tests
  • Assuming JaCoCo replaces JUnit
2. Which of the following is the correct way to add JaCoCo plugin in a Maven pom.xml file?
easy
A. org.jacoco jacoco-maven-plugin 0.8.8
B. org.junit.jupiter junit-jupiter-engine 5.9.2
C. org.jacoco jacoco-core 0.8.8
D. org.apache.maven.plugins maven-compiler-plugin 3.8.1

Solution

  1. Step 1: Identify JaCoCo plugin syntax

    JaCoCo is added as a Maven plugin with groupId 'org.jacoco' and artifactId 'jacoco-maven-plugin'.
  2. Step 2: Eliminate incorrect options

    Options B and D are unrelated plugins; A is a dependency, not a plugin.
  3. Final Answer:

    Correct JaCoCo plugin configuration in Maven -> Option A
  4. Quick Check:

    JaCoCo plugin = org.jacoco:jacoco-maven-plugin [OK]
Hint: JaCoCo is a plugin, not a dependency in Maven [OK]
Common Mistakes:
  • Adding JaCoCo as a dependency instead of plugin
  • Confusing JUnit plugin with JaCoCo plugin
  • Using unrelated Maven plugins
3. Given the following JaCoCo configuration snippet in a Maven pom.xml:
<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>
What will happen when you run mvn test?
medium
A. JaCoCo agent prepares coverage data before tests, then generates a coverage report after tests
B. Tests will run without coverage data collection
C. The build will fail due to missing report goal
D. JaCoCo will only generate a report without running tests

Solution

  1. Step 1: Understand prepare-agent goal

    The 'prepare-agent' goal sets up JaCoCo to collect coverage data during test execution.
  2. Step 2: Understand report goal in test phase

    The 'report' goal runs after tests to generate the coverage report.
  3. Final Answer:

    JaCoCo collects coverage during tests and generates report after -> Option A
  4. Quick Check:

    prepare-agent + report = coverage data + report [OK]
Hint: prepare-agent collects data; report generates coverage output [OK]
Common Mistakes:
  • Assuming coverage is collected without prepare-agent
  • Thinking report runs before tests
  • Confusing goals causing build failure
4. You added JaCoCo plugin to your Maven project but no coverage report is generated after running mvn test. What is the most likely cause?
medium
A. JUnit tests are not written correctly
B. You used an incorrect JaCoCo version number
C. You forgot to bind the report goal to the test phase
D. Maven compiler plugin is missing

Solution

  1. Step 1: Check JaCoCo execution bindings

    Without binding the 'report' goal to the 'test' phase, JaCoCo won't generate reports automatically.
  2. Step 2: Eliminate other causes

    Incorrect version usually causes build errors; test correctness or compiler plugin absence won't stop report generation if configured.
  3. Final Answer:

    Missing binding of report goal to test phase -> Option C
  4. Quick Check:

    Report goal must be bound to test phase [OK]
Hint: Bind report goal to test phase to generate coverage report [OK]
Common Mistakes:
  • Ignoring execution phase bindings
  • Blaming test code for missing reports
  • Assuming version mismatch causes silent failure
5. You want to configure JaCoCo in a Gradle project to generate an XML coverage report after tests run. Which snippet correctly configures this in build.gradle?
hard
A. jacocoTestReport { reports { xml.required = true html.required = false } }
B. jacocoTestReport { reports { xml.enabled = true html.enabled = true } }
C. test { useJUnitPlatform() jacoco { xml.enabled = true } }
D. jacoco { toolVersion = '0.8.8' reports { xml.enabled = true } }

Solution

  1. Step 1: Identify correct JaCoCo Gradle report syntax

    The 'jacocoTestReport' task configures reports with 'xml.enabled' and 'html.enabled' properties.
  2. Step 2: Compare options for XML report generation

    jacocoTestReport { reports { xml.enabled = true html.enabled = true } } correctly enables XML report; the snippet using 'required' properties is outdated; others configure in wrong blocks.
  3. Final Answer:

    jacocoTestReport with reports { xml.enabled = true } -> Option B
  4. Quick Check:

    Use xml.enabled = true in jacocoTestReport [OK]
Hint: Use xml.enabled = true inside jacocoTestReport for XML reports [OK]
Common Mistakes:
  • Using xml.required instead of xml.enabled
  • Configuring jacoco block instead of jacocoTestReport
  • Missing enabling of reports
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard