@EnabledIfSystemProperty(named = "os.name", matches = "Windows.*") do when applied to a test method?matches attribute uses regular expressions.The annotation @EnabledIfSystemProperty runs the test only if the specified system property matches the given regular expression. Here, matches = "Windows.*" means the property value must start with "Windows".
os.name is "Linux"?import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledIfSystemProperty; public class SystemPropertyTest { @Test @EnabledIfSystemProperty(named = "os.name", matches = "Windows.*") void testWindowsOnly() { System.out.println("Windows test executed"); } @Test void testAlways() { System.out.println("Always executed"); } }
The test annotated with @EnabledIfSystemProperty runs only if os.name matches "Windows.*". On Linux, it does not match, so that test is skipped. The other test runs always.
@EnabledIfSystemProperty(named = "env", matches = "prod") runs only when the system property env is set to "prod"?The matches attribute expects the system property to exactly match "prod". The assertion must check equality, not containment or null.
@EnabledIfSystemProperty(named = "user.language", matches = "en") is unexpectedly skipped on a machine where user.language is "en_US". What is the most likely cause?The matches attribute uses Java regex which must match the entire string. "en" matches only the exact string "en", not "en_US".
@EnabledIfSystemProperty(named = "env", matches = "prod") and @EnabledOnOs(OS.WINDOWS). Under which condition will this test run?JUnit requires all conditional annotations on a test to be true for the test to run. Both conditions must be met.