Recall & Review
beginner
What is the purpose of the
@EnabledOnOs annotation in JUnit?It allows a test to run only on specified operating systems, skipping it on others. This helps test OS-specific features or behaviors.
Click to reveal answer
beginner
How do you specify multiple operating systems with
@EnabledOnOs?You list them inside the annotation using the
value attribute, for example: @EnabledOnOs({OS.WINDOWS, OS.LINUX}).Click to reveal answer
beginner
What happens if a test annotated with
@EnabledOnOs(OS.MAC) runs on Windows?The test is skipped and not executed because the current OS does not match the specified one.
Click to reveal answer
beginner
Write a simple JUnit 5 test method that runs only on Linux using
@EnabledOnOs.```java
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledOnOs;
import org.junit.jupiter.api.condition.OS;
class MyTests {
@Test
@EnabledOnOs(OS.LINUX)
void testOnlyOnLinux() {
// test code here
}
}
```Click to reveal answer
beginner
Why is it useful to run tests only on specific operating systems?
Because some features or bugs appear only on certain OSes. Running OS-specific tests prevents false failures on unsupported systems and saves test time.
Click to reveal answer
Which annotation runs a JUnit test only on Windows OS?
✗ Incorrect
The correct annotation to enable a test only on Windows is @EnabledOnOs(OS.WINDOWS).
What happens if a test annotated with @EnabledOnOs(OS.LINUX) runs on Mac?
✗ Incorrect
The test is skipped because the OS does not match the specified Linux OS.
How do you specify multiple OSes in @EnabledOnOs?
✗ Incorrect
Multiple OSes are specified as an array: @EnabledOnOs({OS.WINDOWS, OS.MAC}).
Which package contains the @EnabledOnOs annotation?
✗ Incorrect
@EnabledOnOs is in the package org.junit.jupiter.api.condition.
Why might you want to skip tests on certain OSes?
✗ Incorrect
All these reasons justify skipping tests on unsupported OSes.
Explain how to use @EnabledOnOs to run a test only on Windows and Mac OS.
Think about how to list multiple OS values inside the annotation.
You got /4 concepts.
Describe the benefits of using OS-specific test annotations like @EnabledOnOs in your test suite.
Consider how different OSes can affect software behavior and testing.
You got /4 concepts.