Environment Variable Conditions - @DisabledIfEnvironmentVariable and @EnabledIfEnvironmentVariable

This lesson demonstrates how to disable or enable test methods or a complete test class using Environment variable conditions.

@DisabledIfEnvironmentVariable and @EnabledIfEnvironmentVariable

Junit 5 helps us to disable or enable test cases using various conditions. JUnit Jupiter API provides annotations in org.junit.jupiter.api.condition package to enable/disable tests based on a certain condition. The annotations provided by API can be applied to test methods as well as the class itself. The two annotations which use system environment properties and specified regex to disable or enable tests are - @DisabledIfEnvironmentVariable and @EnabledIfEnvironmentVariable. Let’s take a look at a demo.

Get hands-on with 1400+ tech skills courses.