0
0
JUnittesting~10 mins

Code quality gates 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 assert that the method returns true.

JUnit
assertTrue([1]());
Drag options to blanks, or click blank then click option'
AisCodeQualityPassed
BvalidateCode
CcheckQuality
DrunQualityGate
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method that does not return a boolean.
Forgetting to call the method with parentheses.
2fill in blank
medium

Complete the code to fail the test if the code quality gate is not met.

JUnit
if (![1]()) {
    fail("Code quality gate failed");
}
Drag options to blanks, or click blank then click option'
AcheckQualityGate
BisCodeQualityPassed
CvalidateQuality
DrunQualityCheck
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method that does not return a boolean.
Not negating the condition to fail when quality gate fails.
3fill in blank
hard

Fix the error in the assertion to check that the quality gate score is above 80.

JUnit
assertTrue(qualityGate.getScore() [1] 80);
Drag options to blanks, or click blank then click option'
A==
B<
C>
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using less than operator which fails the test when score is high.
Using equality operator which is too strict.
4fill in blank
hard

Fill both blanks to create a test that asserts the quality gate status is 'PASSED' and the score is at least 90.

JUnit
assertEquals("[1]", qualityGate.getStatus());
assertTrue(qualityGate.getScore() [2] 90);
Drag options to blanks, or click blank then click option'
APASSED
B>=
C>
DFAILED
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'FAILED' instead of 'PASSED' for status.
Using '>' instead of '>=' for score comparison.
5fill in blank
hard

Fill all three blanks to create a test that checks the quality gate status is 'PASSED', the score is above 85, and the error count is zero.

JUnit
assertEquals("[1]", qualityGate.getStatus());
assertTrue(qualityGate.getScore() [2] 85);
assertEquals([3], qualityGate.getErrorCount());
Drag options to blanks, or click blank then click option'
APASSED
B>
C0
DFAILED
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'FAILED' instead of 'PASSED' for status.
Using '>=' instead of '>' for score comparison.
Using 1 instead of 0 for error count.