Annotation Type DisableIfTestFails


  • @Retention(RUNTIME)
    @Target(TYPE)
    @Inherited
    @ExtendWith(DisableIfTestFailsExtension.class)
    public @interface DisableIfTestFails
    Disables all remaining tests in a container if one of them failed.

    By default, all exceptions (including assertions, but exempting failed assumptions) will lead to disabling the remaining tests. To configure this in more detail, see with() and onAssertion().

    This annotation can be (meta-)present on classes that contain a nested class. In that case, a failing test in the outer class will disable the nested class (if it runs later) and vice versa.

    This annotation can be (meta-)present on a class and/or its super types (classes or interfaces). In that case, the exception types given to with() are merged and onAssertion() is or'ed.

    But if a test fails in a specific class, only other tests in the corresponding container will be disabled. That means if...

    • a class SpecificTests implements interface Tests and
    • Tests is annotated with @DisableIfTestFails and
    • a test in SpecificTests fails
    ... then, only remaining tests in SpecificTests are disabled and other implementations of Tests remain unaffected, i.e. their tests are not disabled.
    • Optional Element Summary

      Optional Elements 
      Modifier and Type Optional Element Description
      boolean onAssertion
      Set to false if failed assertions should not lead to disabling remaining tests.
      java.lang.Class<? extends java.lang.Throwable>[] with
      Configure on which exceptions remaining tests are disabled (defaults to "any exception").
    • Element Detail

      • with

        java.lang.Class<? extends java.lang.Throwable>[] with
        Configure on which exceptions remaining tests are disabled (defaults to "any exception").

        If @DisableIfTestFails is present multiple times (e.g. on multiple super types), these exceptions are collected across all annotations, meaning if any of the mentioned exceptions are thrown, the remaining tests are disabled.

        Default:
        {}
      • onAssertion

        boolean onAssertion
        Set to false if failed assertions should not lead to disabling remaining tests.

        If @DisableIfTestFails is present multiple times (e.g. on multiple super types), this value is or'ed, meaning as soon as one annotation says to fail on assertion errors, that's how the container will behave.

        Default:
        true