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?
✗ Incorrect
The annotation enables the test only if the current runtime is Java 11.
If you want a test to run on Java 8 and Java 17, how do you write @EnabledOnJre?
✗ Incorrect
You must use curly braces to specify multiple JRE versions as an array.
What is the test result if @EnabledOnJre specifies Java 17 but the test runs on Java 11?
✗ Incorrect
The test is skipped because the current JRE does not match the specified version.
Which import is required to use @EnabledOnJre in JUnit 5?
✗ Incorrect
The correct import is from the condition package: org.junit.jupiter.api.condition.EnabledOnJre.
Can @EnabledOnJre be combined with other conditional annotations like @EnabledOnOs?
✗ Incorrect
Multiple conditional annotations can be combined to run tests only when all conditions are met.
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.