Class Assumptions

java.lang.Object
org.junit.jupiter.api.Assumptions

@API(status=STABLE, since="5.0") public class Assumptions extends Object
Assumptions is a collection of utility methods that support conditional test execution based on assumptions.

In direct contrast to failed assertions, failed assumptions do not result in a test failure; rather, a failed assumption results in a test being aborted.

Assumptions are typically used whenever it does not make sense to continue execution of a given test method — for example, if the test depends on something that does not exist in the current runtime environment.

Although it is technically possible to extend this class, extension is strongly discouraged. The JUnit Team highly recommends that the methods defined in this class be used via static imports.

Since:
5.0
See Also:
  • Constructor Details

    • Assumptions

      protected Assumptions()
      Protected constructor allowing subclassing but not direct instantiation.
      Since:
      5.3
  • Method Details

    • assumeTrue

      public static void assumeTrue(boolean assumption) throws TestAbortedException
      Validate the given assumption.
      Parameters:
      assumption - the assumption to validate
      Throws:
      TestAbortedException - if the assumption is not true
    • assumeTrue

      public static void assumeTrue(BooleanSupplier assumptionSupplier) throws TestAbortedException
      Validate the given assumption.
      Parameters:
      assumptionSupplier - the supplier of the assumption to validate
      Throws:
      TestAbortedException - if the assumption is not true
    • assumeTrue

      public static void assumeTrue(BooleanSupplier assumptionSupplier, String message) throws TestAbortedException
      Validate the given assumption.
      Parameters:
      assumptionSupplier - the supplier of the assumption to validate
      message - the message to be included in the TestAbortedException if the assumption is invalid
      Throws:
      TestAbortedException - if the assumption is not true
    • assumeTrue

      public static void assumeTrue(boolean assumption, Supplier<String> messageSupplier) throws TestAbortedException
      Validate the given assumption.
      Parameters:
      assumption - the assumption to validate
      messageSupplier - the supplier of the message to be included in the TestAbortedException if the assumption is invalid
      Throws:
      TestAbortedException - if the assumption is not true
    • assumeTrue

      public static void assumeTrue(boolean assumption, String message) throws TestAbortedException
      Validate the given assumption.
      Parameters:
      assumption - the assumption to validate
      message - the message to be included in the TestAbortedException if the assumption is invalid
      Throws:
      TestAbortedException - if the assumption is not true
    • assumeTrue

      public static void assumeTrue(BooleanSupplier assumptionSupplier, Supplier<String> messageSupplier) throws TestAbortedException
      Validate the given assumption.
      Parameters:
      assumptionSupplier - the supplier of the assumption to validate
      messageSupplier - the supplier of the message to be included in the TestAbortedException if the assumption is invalid
      Throws:
      TestAbortedException - if the assumption is not true
    • assumeFalse

      public static void assumeFalse(boolean assumption) throws TestAbortedException
      Validate the given assumption.
      Parameters:
      assumption - the assumption to validate
      Throws:
      TestAbortedException - if the assumption is not false
    • assumeFalse

      public static void assumeFalse(BooleanSupplier assumptionSupplier) throws TestAbortedException
      Validate the given assumption.
      Parameters:
      assumptionSupplier - the supplier of the assumption to validate
      Throws:
      TestAbortedException - if the assumption is not false
    • assumeFalse

      public static void assumeFalse(BooleanSupplier assumptionSupplier, String message) throws TestAbortedException
      Validate the given assumption.
      Parameters:
      assumptionSupplier - the supplier of the assumption to validate
      message - the message to be included in the TestAbortedException if the assumption is invalid
      Throws:
      TestAbortedException - if the assumption is not false
    • assumeFalse

      public static void assumeFalse(boolean assumption, Supplier<String> messageSupplier) throws TestAbortedException
      Validate the given assumption.
      Parameters:
      assumption - the assumption to validate
      messageSupplier - the supplier of the message to be included in the TestAbortedException if the assumption is invalid
      Throws:
      TestAbortedException - if the assumption is not false
    • assumeFalse

      public static void assumeFalse(boolean assumption, String message) throws TestAbortedException
      Validate the given assumption.
      Parameters:
      assumption - the assumption to validate
      message - the message to be included in the TestAbortedException if the assumption is invalid
      Throws:
      TestAbortedException - if the assumption is not false
    • assumeFalse

      public static void assumeFalse(BooleanSupplier assumptionSupplier, Supplier<String> messageSupplier) throws TestAbortedException
      Validate the given assumption.
      Parameters:
      assumptionSupplier - the supplier of the assumption to validate
      messageSupplier - the supplier of the message to be included in the TestAbortedException if the assumption is invalid
      Throws:
      TestAbortedException - if the assumption is not false
    • assumingThat

      public static void assumingThat(BooleanSupplier assumptionSupplier, Executable executable)
      Execute the supplied Executable, but only if the supplied assumption is valid.

      Unlike the other assumption methods, this method will not abort the test. If the assumption is invalid, this method does nothing. If the assumption is valid and the executable throws an exception, it will be treated like a regular test failure. That exception will be rethrown as is but masked as an unchecked exception.

      Parameters:
      assumptionSupplier - the supplier of the assumption to validate
      executable - the block of code to execute if the assumption is valid
      See Also:
    • assumingThat

      public static void assumingThat(boolean assumption, Executable executable)
      Execute the supplied Executable, but only if the supplied assumption is valid.

      Unlike the other assumption methods, this method will not abort the test. If the assumption is invalid, this method does nothing. If the assumption is valid and the executable throws an exception, it will be treated like a regular test failure. That exception will be rethrown as is but masked as an unchecked exception.

      Parameters:
      assumption - the assumption to validate
      executable - the block of code to execute if the assumption is valid
      See Also: