JUnit 5 Conditional Tests - @EnabledOnOs, @EnabledOnJre, @EnabledIfEnvironmentVariable
Deciding whether tests run based on OS, Java version, system properties, and environment variables
Conditional Tests
Test code can be enabled or disabled depending on conditions such as OS, Java version, system properties, or environment variables.
Tests by OS
Use @EnabledOnOs and @DisabledOnOs to run or skip tests for a specific OS. Specify an OS constant in value.
Java Version
Use @EnabledOnJre and @DisabledOnJre to run or skip tests for a specific Java version. Specify a JRE constant in value.
System Properties
Use @EnabledIfSystemProperty and @DisabledIfSystemProperty to control execution by system property values.
namedspecifies the system property name.matchesspecifies the expected value as a regular expression.
Environment Variables
Use @EnabledIfEnvironmentVariable and @DisabledIfEnvironmentVariable to control execution by environment variable values.
namedspecifies the environment variable name.matchesspecifies the expected value as a regular expression.