Challenge - 5 Problems
JRE Conditional Testing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of a test annotated with @EnabledOnJre for Java 17
Consider this JUnit 5 test class snippet. What will be the test execution result if run on Java 17?
JUnit
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledOnJre; import org.junit.jupiter.api.condition.JRE; public class SampleTest { @Test @EnabledOnJre(JRE.JAVA_17) void testOnlyOnJava17() { System.out.println("Running on Java 17"); } @Test void alwaysRun() { System.out.println("Always runs"); } }
Attempts:
2 left
💡 Hint
Think about what @EnabledOnJre does and which tests have it.
✗ Incorrect
The test annotated with @EnabledOnJre(JRE.JAVA_17) runs only on Java 17. The other test runs always. So on Java 17 both run.
❓ assertion
intermediate2:00remaining
Correct assertion to verify @EnabledOnJre disables test on Java 11
You want to assert that a test annotated with @EnabledOnJre(JRE.JAVA_17) does NOT run on Java 11. Which assertion correctly verifies this behavior in a test suite?
Attempts:
2 left
💡 Hint
If the test is disabled, it should not have executed.
✗ Incorrect
On Java 11, the test with @EnabledOnJre(JRE.JAVA_17) is disabled, so testExecuted should be false.
🔧 Debug
advanced2:00remaining
Why does @EnabledOnJre not disable test on Java 18?
Given this test annotation: @EnabledOnJre(JRE.JAVA_17), why does the test still run on Java 18?
Attempts:
2 left
💡 Hint
Check how @EnabledOnJre matches JRE versions exactly.
✗ Incorrect
The annotation matches only the exact JRE version specified. Java 18 is different from Java 17, so the test is disabled on Java 18.
🧠 Conceptual
advanced2:00remaining
Purpose of @EnabledOnJre in test suites
What is the main purpose of using @EnabledOnJre in JUnit test suites?
Attempts:
2 left
💡 Hint
Think about controlling test execution based on Java version.
✗ Incorrect
The annotation controls test execution so tests run only on specified Java versions.
❓ framework
expert2:00remaining
Combining @EnabledOnJre with other conditional annotations
You want a test to run only on Java 17 and only on Windows OS. Which annotation combination correctly achieves this in JUnit 5?
Attempts:
2 left
💡 Hint
Use separate annotations for JRE and OS conditions.
✗ Incorrect
JUnit 5 requires separate annotations for JRE and OS conditions. Option B correctly uses @EnabledOnJre and @EnabledOnOs separately.