0
0
JUnittesting~20 mins

Coverage thresholds in JUnit - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Coverage Threshold Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
JUnit Coverage Threshold Failure Output
Given the following JUnit test coverage configuration, what will be the test execution result if the coverage is 74% for branch coverage?
JUnit
jacoco {
  toolVersion = "0.8.8"
  reports {
    xml.required.set(true)
    html.required.set(true)
  }
  coverageVerification {
    violationRules {
      rule {
        limit {
          counter = 'BRANCH'
          value = 'COVERED_RATIO'
          minimum = '0.75'
        }
      }
    }
  }
}
ATest execution passes but with a warning about coverage.
BTest execution passes successfully with no errors.
CTest execution is skipped because coverage is below threshold.
DTest execution fails due to branch coverage below 75%.
Attempts:
2 left
💡 Hint
Coverage verification rules enforce minimum coverage thresholds strictly.
assertion
intermediate
1:30remaining
Assertion on Coverage Percentage in JUnit Test Report
Which assertion correctly verifies that the line coverage percentage is at least 80% in a JUnit test report parsed as a float variable named coverageLinePercent?
AassertFalse(coverageLinePercent < 80.0);
BassertEquals(coverageLinePercent, 80.0);
CassertTrue(coverageLinePercent >= 80.0);
DassertNotNull(coverageLinePercent > 80.0);
Attempts:
2 left
💡 Hint
Use an assertion that checks a condition is true for coverage threshold.
🔧 Debug
advanced
2:00remaining
Debugging Coverage Threshold Failure in JUnit
A JUnit test suite fails with a coverage threshold violation error, but the reported coverage is 85%. What is the most likely cause?
AThe coverage report file is missing or corrupted, causing a false failure.
BThe coverage threshold is set higher than 85%, causing failure.
CThe test suite has syntax errors unrelated to coverage.
DJUnit does not support coverage thresholds, so the error is invalid.
Attempts:
2 left
💡 Hint
Check the configured minimum coverage value in the build tool.
framework
advanced
2:30remaining
Configuring Coverage Thresholds in JUnit with JaCoCo
Which snippet correctly configures JaCoCo in a Gradle build to fail the build if instruction coverage is below 90%?
A
jacocoTestCoverageVerification {
  violationRules {
    rule {
      limit {
        counter = 'INSTRUCTION'
        value = 'COVERED_RATIO'
        minimum = '0.9'
      }
    }
  }
}
B
jacocoTestCoverageVerification {
  violationRules {
    rule {
      limit {
        counter = 'INSTRUCTION'
        value = 'COVERED_RATIO'
        minimum = 0.9
      }
    }
  }
}
C
jacocoTestCoverageVerification {
  violationRules {
    rule {
      limit {
        counter = 'INSTRUCTION'
        value = 'COVERED_PERCENTAGE'
        minimum = '90'
      }
    }
  }
}
D
jacocoTestCoverageVerification {
  violationRules {
    rule {
      limit {
        counter = 'INSTRUCTION'
        value = 'COVERED_RATIO'
        minimum = 90
      }
    }
  }
}
Attempts:
2 left
💡 Hint
Minimum must be a string representing a decimal ratio between 0 and 1.
🧠 Conceptual
expert
3:00remaining
Impact of Coverage Thresholds on Continuous Integration
Which statement best describes the impact of strict coverage thresholds in a CI pipeline using JUnit and JaCoCo?
AStrict thresholds ensure high code quality but may cause frequent build failures requiring quick fixes.
BStrict thresholds have no impact on build stability or developer workflow.
CStrict thresholds automatically fix coverage gaps without developer intervention.
DStrict thresholds reduce test execution time by skipping low coverage tests.
Attempts:
2 left
💡 Hint
Consider how coverage enforcement affects build success and developer actions.