0
0
JUnittesting~10 mins

Coverage reports in JUnit - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to generate a coverage report using JaCoCo in a Maven project.

JUnit
<plugin>
  <groupId>org.jacoco</groupId>
  <artifactId>jacoco-maven-plugin</artifactId>
  <version>0.8.8</version>
  <executions>
    <execution>
      <goals>
        <goal>[1]</goal>
      </goals>
    </execution>
  </executions>
</plugin>
Drag options to blanks, or click blank then click option'
Apackage
Bcompile
Ctest
Dprepare-agent
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'test' instead of 'prepare-agent' causes no coverage data to be collected.
Using 'compile' or 'package' does not start the coverage agent.
2fill in blank
medium

Complete the code to generate the coverage report after tests run.

JUnit
<execution>
  <id>report</id>
  <phase>[1]</phase>
  <goals>
    <goal>report</goal>
  </goals>
</execution>
Drag options to blanks, or click blank then click option'
Atest
Bcompile
Cverify
Dinstall
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'test' phase generates report too early before tests finish.
Using 'compile' phase is before tests run.
3fill in blank
hard

Fix the error in the JaCoCo plugin configuration to correctly bind the report goal.

JUnit
<execution>
  <id>default-report</id>
  <phase>[1]</phase>
  <goals>
    <goal>report</goal>
  </goals>
</execution>
Drag options to blanks, or click blank then click option'
Averify
Bprepare-package
Ctest
Dcompile
Attempts:
3 left
💡 Hint
Common Mistakes
Binding to 'test' phase causes report generation before tests finish.
Binding to 'compile' phase is before tests run.
4fill in blank
hard

Fill both blanks to create a JaCoCo report that includes XML and HTML formats.

JUnit
<configuration>
  <formats>
    <format>[1]</format>
    <format>[2]</format>
  </formats>
</configuration>
Drag options to blanks, or click blank then click option'
Axml
Bcsv
Chtml
Dtxt
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'csv' or 'txt' causes errors as they are unsupported formats.
Using only one format misses the other common report type.
5fill in blank
hard

Fill all three blanks to configure JaCoCo to fail the build if coverage is below 80%.

JUnit
<configuration>
  <rules>
    <rule>
      <element>[1]</element>
      <limits>
        <limit>
          <counter>[2]</counter>
          <value>[3]</value>
          <minimum>0.80</minimum>
        </limit>
      </limits>
    </rule>
  </rules>
</configuration>
Drag options to blanks, or click blank then click option'
ACLASS
BLINE
CINSTRUCTION
DCOVEREDRATIO
Attempts:
3 left
💡 Hint
Common Mistakes
Using unsupported elements or counters causes configuration errors.
Setting minimum above 1.0 or below 0 causes invalid rules.