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.

  • named specifies the system property name.
  • matches specifies the expected value as a regular expression.

Environment Variables

Use @EnabledIfEnvironmentVariable and @DisabledIfEnvironmentVariable to control execution by environment variable values.

  • named specifies the environment variable name.
  • matches specifies the expected value as a regular expression.