0
0
JUnittesting~10 mins

Coverage thresholds 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 set the minimum line coverage threshold to 80%.

JUnit
@Rule
public final TestRule coverage = new CoverageRule().withLineThreshold([1]);
Drag options to blanks, or click blank then click option'
A75
B90
C80
D70
Attempts:
3 left
💡 Hint
Common Mistakes
Using a value less than desired threshold like 70 instead of 80.
Including the % sign in the number.
2fill in blank
medium

Complete the code to fail the test if branch coverage is below 85%.

JUnit
@Rule
public final TestRule coverage = new CoverageRule().withBranchThreshold([1]);
Drag options to blanks, or click blank then click option'
A80
B85
C90
D75
Attempts:
3 left
💡 Hint
Common Mistakes
Setting the threshold too low, which may allow insufficient coverage.
Confusing line coverage with branch coverage.
3fill in blank
hard

Fix the error in the code to correctly set the coverage threshold to 75%.

JUnit
@Rule
public final TestRule coverage = new CoverageRule().withLineThreshold([1]);
Drag options to blanks, or click blank then click option'
A75
B"75%"
C0.75
DseventyFive
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string with % sign like "75%".
Using a decimal like 0.75 instead of 75.
4fill in blank
hard

Fill both blanks to set line coverage to 80% and branch coverage to 70%.

JUnit
@Rule
public final TestRule coverage = new CoverageRule()
    .withLineThreshold([1])
    .withBranchThreshold([2]);
Drag options to blanks, or click blank then click option'
A80
B70
C75
D85
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the values between line and branch thresholds.
Using values outside typical coverage ranges.
5fill in blank
hard

Fill all three blanks to set line coverage to 85%, branch coverage to 80%, and fail on uncovered methods.

JUnit
@Rule
public final TestRule coverage = new CoverageRule()
    .withLineThreshold([1])
    .withBranchThreshold([2])
    .failOnUncoveredMethods([3]);
Drag options to blanks, or click blank then click option'
Atrue
Bfalse
C80
D85
Attempts:
3 left
💡 Hint
Common Mistakes
Using false instead of true for failOnUncoveredMethods.
Mixing up the coverage threshold values.