Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to enable the test only on Java 17.
JUnit
@EnabledOnJre({JRE.[1])
void testFeature() {
// test code here
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a Java version constant that does not match the intended JRE version.
Forgetting to import the JRE enum.
✗ Incorrect
The @EnabledOnJre annotation uses JRE constants like JAVA_17 to specify the Java version for which the test runs.
2fill in blank
mediumComplete the code to enable the test only on Java 11 and Java 17.
JUnit
@EnabledOnJre({JRE.JAVA_11, JRE.[1])
void testMultipleVersions() {
// test code here
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a version not supported or not intended for the test.
Syntax errors in the array of JRE versions.
✗ Incorrect
You can specify multiple JRE versions in the @EnabledOnJre annotation by listing them in the array.
3fill in blank
hardFix the error in the annotation to correctly enable the test on Java 8.
JUnit
@EnabledOnJre(JRE.[1])
void testLegacySupport() {
// test code here
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using JAVA8 without underscore causes a compile error.
Using hyphens or trailing underscores is invalid.
✗ Incorrect
The correct enum constant for Java 8 is JAVA_8 with an underscore, not JAVA8 or other variants.
4fill in blank
hardFill both blanks to enable the test only on Java 15 or Java 19.
JUnit
@EnabledOnJre({JRE.[1], JRE.[2])
void testFutureVersions() {
// test code here
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing older versions like Java 8 or 11 when the test targets newer versions.
Syntax errors in the array notation.
✗ Incorrect
The test is enabled on Java 15 and Java 19 by listing both versions in the annotation array.
5fill in blank
hardFill all three blanks to enable the test on Java 8, Java 11, and Java 17.
JUnit
@EnabledOnJre({JRE.[1], JRE.[2], JRE.[3])
void testMultipleLTS() {
// test code here
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to close the array with a closing brace.
Using incorrect enum constants or missing commas.
✗ Incorrect
The annotation enables the test on three LTS Java versions by listing them all in the array.