Test Overview
This test checks that a method runs only on Windows OS using the @EnabledOnOs annotation. It verifies the test is skipped on other operating systems.
This test checks that a method runs only on Windows OS using the @EnabledOnOs annotation. It verifies the test is skipped on other operating systems.
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledOnOs; import org.junit.jupiter.api.condition.OS; import static org.junit.jupiter.api.Assertions.assertTrue; public class OsSpecificTest { @Test @EnabledOnOs(OS.WINDOWS) void testRunsOnlyOnWindows() { String osName = System.getProperty("os.name").toLowerCase(); assertTrue(osName.contains("windows"), "Test should run only on Windows OS"); } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test runner starts and detects the test method annotated with @EnabledOnOs(OS.WINDOWS) | JUnit test environment initialized | - | PASS |
| 2 | JUnit checks the current OS from System.getProperty("os.name") | System property os.name is read, e.g., "Windows 10" or "Linux" | - | PASS |
| 3 | JUnit compares current OS with the annotation condition (Windows) | OS matches Windows if running on Windows, else does not match | - | PASS |
| 4 | If OS matches Windows, test method executes and asserts os.name contains "windows" | Test method runs on Windows OS | assertTrue(osName.contains("windows")) | PASS |
| 5 | If OS does not match Windows, test is skipped by JUnit | Test method is not executed on non-Windows OS | - | PASS |