5.3. Conditional Test Execution
[ExecutionCondition](https://junit.org/junit5/docs/current/api/org.junit.jupiter.api/org/junit/jupiter/api/extension/ExecutionCondition.html)
defines the Extension
API for programmatic, conditional test execution.
An ExecutionCondition
is evaluated for each container (e.g., a test class) to determine if all the tests it contains should be executed based on the supplied ExtensionContext
. Similarly, an ExecutionCondition
is evaluated for each test to determine if a given test method should be executed based on the supplied ExtensionContext
.
When multiple ExecutionCondition
extensions are registered, a container or test is disabled as soon as one of the conditions returns disabled. Thus, there is no guarantee that a condition is evaluated because another extension might have already caused a container or test to be disabled. In other words, the evaluation works like the short-circuiting boolean OR operator.
See the source code of [DisabledCondition](https://github.com/junit-team/junit5/tree/r5.7.0/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/extension/DisabledCondition.java)
and [@Disabled](https://junit.org/junit5/docs/current/api/org.junit.jupiter.api/org/junit/jupiter/api/Disabled.html)
for concrete examples.
5.3.1. Deactivating Conditions
Sometimes it can be useful to run a test suite without certain conditions being active. For example, you may wish to run tests even if they are annotated with @Disabled
in order to see if they are still broken. To do this, provide a pattern for the junit.jupiter.conditions.deactivate
configuration parameter to specify which conditions should be deactivated (i.e., not evaluated) for the current test run. The pattern can be supplied as a JVM system property, as a configuration parameter in the LauncherDiscoveryRequest
that is passed to the Launcher
, or via the JUnit Platform configuration file (see Configuration Parameters for details).
For example, to deactivate JUnit’s @Disabled
condition, you can start your JVM with the following system property.
-Djunit.jupiter.conditions.deactivate=org.junit.*DisabledCondition
Pattern Matching Syntax
Refer to Pattern Matching Syntax for details.