Test Overview
This test checks if a method runs only when a specific system property is set to a certain value. It verifies conditional test execution based on system properties.
This test checks if a method runs only when a specific system property is set to a certain value. It verifies conditional test execution based on system properties.
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledIfSystemProperty; import static org.junit.jupiter.api.Assertions.assertTrue; public class SystemPropertyTest { @Test @EnabledIfSystemProperty(named = "env", matches = "dev") void testRunsOnlyOnDev() { String env = System.getProperty("env"); assertTrue("dev".equals(env)); } }
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test framework starts and reads test annotations | JUnit test runner initialized | - | PASS |
| 2 | Check system property 'env' value | System property 'env' is set to 'dev' | System.getProperty('env') == 'dev' | PASS |
| 3 | Since property matches, testRunsOnlyOnDev() is executed | Inside test method | assertTrue("dev".equals(env)) | PASS |
| 4 | Test completes successfully | Test passed | - | PASS |