0
0
JUnittesting~5 mins

@EnabledOnJre for JRE-specific tests in JUnit - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the @EnabledOnJre annotation in JUnit?
The @EnabledOnJre annotation is used to run a test only on specific Java Runtime Environment (JRE) versions. It helps to conditionally enable tests based on the JRE version.
Click to reveal answer
intermediate
How do you specify multiple JRE versions with @EnabledOnJre?
You specify multiple JRE versions by listing them inside the annotation like @EnabledOnJre({JRE.JAVA_8, JRE.JAVA_11}). The test will run only if the current JRE matches any of these versions.
Click to reveal answer
beginner
Write a simple example of a test method enabled only on Java 17 using @EnabledOnJre.
```java @EnabledOnJre(JRE.JAVA_17) void testOnlyOnJava17() { // test code here } ```
Click to reveal answer
beginner
What happens if a test annotated with @EnabledOnJre runs on a non-specified JRE version?
The test is skipped and marked as disabled in the test report. It does not fail or pass; it simply does not run.
Click to reveal answer
intermediate
Why is it useful to use @EnabledOnJre in testing?
It helps avoid test failures caused by differences in JRE versions. Some features or behaviors may only exist in certain JREs, so this annotation ensures tests run only where they make sense.
Click to reveal answer
What does @EnabledOnJre(JRE.JAVA_11) do?
ARuns the test on all JRE versions except Java 11
BRuns the test only on Java 11 runtime
CDisables the test on Java 11 runtime
DRuns the test only on Java 8 runtime
If you want a test to run on Java 8 and Java 17, how do you write @EnabledOnJre?
A@EnabledOnJre(JRE.JAVA_8 || JRE.JAVA_17)
B@EnabledOnJre(JRE.JAVA_8, JRE.JAVA_17)
C@EnabledOnJre({JRE.JAVA_8, JRE.JAVA_17})
D@EnabledOnJre(JRE.JAVA_8 && JRE.JAVA_17)
What is the test result if @EnabledOnJre specifies Java 17 but the test runs on Java 11?
ATest is skipped
BTest passes
CTest fails
DTest runs with warning
Which import is required to use @EnabledOnJre in JUnit 5?
Aimport org.junit.jupiter.api.condition.EnabledOnJre;
Bimport org.junit.jupiter.api.EnabledOnJre;
Cimport org.junit.jupiter.api.condition.JreVersion;
Dimport org.junit.jupiter.api.condition.EnableOnJre;
Can @EnabledOnJre be combined with other conditional annotations like @EnabledOnOs?
ANo, it causes a compilation error
BNo, only one conditional annotation is allowed
CYes, but only if they specify the same condition
DYes, they can be combined to narrow test execution conditions
Explain how @EnabledOnJre helps manage tests across different Java versions.
Think about why some tests might fail on older or newer Java versions.
You got /4 concepts.
    Describe how to write a test that runs only on Java 8 and Java 11 using @EnabledOnJre.
    Remember the syntax for multiple values in annotations.
    You got /4 concepts.