Annotation Interface DisabledIf


@Target({TYPE,METHOD}) @Retention(RUNTIME) @Documented @ExtendWith(org.junit.jupiter.api.condition.DisabledIfCondition.class) @API(status=STABLE, since="5.7") public @interface DisabledIf
@DisabledIf is used to signal that the annotated test class or test method is disabled only if the provided condition evaluates to true.

When applied at the class level, all test methods within that class will be disabled on the same condition.

This annotation is not @Inherited. Consequently, if you wish to apply the same semantics to a subclass, this annotation must be redeclared on the subclass.

If a test method is disabled via this annotation, that does not prevent the test class from being instantiated. Rather, it prevents the execution of the test method and method-level lifecycle callbacks such as @BeforeEach methods, @AfterEach methods, and corresponding extension APIs.

This annotation may be used as a meta-annotation in order to create a custom composed annotation that inherits the semantics of this annotation.

Warning

This annotation can only be declared once on an AnnotatedElement (i.e., test interface, test class, or test method). If this annotation is directly present, indirectly present, or meta-present multiple times on a given element, only the first such annotation discovered by JUnit will be used; any additional declarations will be silently ignored. Note, however, that this annotation may be used in conjunction with other @Enabled* or @Disabled* annotations in this package.
Since:
5.7
See Also:
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    The name of a method within the test class or in an external class to use as a condition for the test's or container's execution.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    Custom reason to provide if the test or container is disabled.
  • Element Details

    • value

      String value
      The name of a method within the test class or in an external class to use as a condition for the test's or container's execution.

      Condition methods must be static if located outside the test class or if @DisabledIf is used at the class level.

      A condition method in an external class must be referenced by its fully qualified method name — for example, com.example.Conditions#isEncryptionSupported.

    • disabledReason

      String disabledReason
      Custom reason to provide if the test or container is disabled.

      If a custom reason is supplied, it will be combined with the default reason for this annotation. If a custom reason is not supplied, the default reason will be used.

      Default:
      ""