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. However, failed assertions and other exceptions thrown by tests take precedence over failed assumptions when both are thrown during the execution of a test (for example, by different lifecycle methods), regardless of the order they are thrown in. In such cases, the test will be reported as failed rather than 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.
TestAbortedException, Assertions
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| public static <V> V | |
| public static <V> V | |
| public static <V> V | |
| public static void | |
| public static void | assumeFalse(BooleanSupplier
the supplier of the assumption to validate assumptionSupplier)Validate the given assumption. |
| public static void | assumeFalse(BooleanSupplier
the supplier of the assumption to validate assumptionSupplier, @Nullable String the message to be included in the message)TestAbortedException
if the assumption is invalidValidate the given assumption. |
| public static void | assumeFalse(boolean
the assumption to validate assumption, Supplier<@Nullable String> the supplier of the message to be included in
the messageSupplier)TestAbortedException if the assumption is invalidValidate the given assumption. |
| public static void | assumeFalse(boolean
the assumption to validate assumption, @Nullable String the message to be included in the message)TestAbortedException
if the assumption is invalidValidate the given assumption. |
| public static void | assumeFalse(BooleanSupplier
the supplier of the assumption to validate assumptionSupplier, Supplier<@Nullable String> the supplier of the message to be included in
the messageSupplier)TestAbortedException if the assumption is invalidValidate the given assumption. |
| public static void | |
| public static void | assumeTrue(BooleanSupplier
the supplier of the assumption to validate assumptionSupplier)Validate the given assumption. |
| public static void | assumeTrue(BooleanSupplier
the supplier of the assumption to validate assumptionSupplier, @Nullable String the message to be included in the message)TestAbortedException
if the assumption is invalidValidate the given assumption. |
| public static void | assumeTrue(boolean
the assumption to validate assumption, Supplier<@Nullable String> the supplier of the message to be included in
the messageSupplier)TestAbortedException if the assumption is invalidValidate the given assumption. |
| public static void | assumeTrue(boolean
the assumption to validate assumption, @Nullable String the message to be included in the message)TestAbortedException
if the assumption is invalidValidate the given assumption. |
| public static void | assumeTrue(BooleanSupplier
the supplier of the assumption to validate assumptionSupplier, Supplier<@Nullable String> the supplier of the message to be included in
the messageSupplier)TestAbortedException if the assumption is invalidValidate the given assumption. |
| public static void | assumingThat(BooleanSupplier
the supplier of the assumption to validate assumptionSupplier, Executable the block of code to execute if the assumption is valid executable)Execute the supplied |
| public static void | assumingThat(boolean
the assumption to validate assumption, Executable the block of code to execute if the assumption is valid executable)Execute the supplied |
| private static void |
| Assumptions | back to summary |
|---|---|
| protected Assumptions() Protected constructor allowing subclassing but not direct instantiation.
| |
| abort | back to summary |
|---|---|
| public static <V> V abort() Abort the test without a message. Although aborting with an explicit message is recommended, this may be useful when maintaining legacy code. See Javadoc for
| |
| abort | back to summary |
|---|---|
| public static <V> V abort(String message) Abort the test with the given The generic return type
| |
| abort | back to summary |
|---|---|
| public static <V> V abort(Supplier<String> messageSupplier) Abort the test with the supplied message. See Javadoc for
| |
| assumeFalse | back to summary |
|---|---|
| public static void assumeFalse(boolean assumption) throws TestAbortedException Validate the given assumption.
| |
| assumeFalse | back to summary |
|---|---|
| public static void assumeFalse(BooleanSupplier assumptionSupplier) throws TestAbortedException Validate the given assumption.
| |
| assumeFalse | back to summary |
|---|---|
| public static void assumeFalse(BooleanSupplier assumptionSupplier, @Nullable String message) throws TestAbortedException Validate the given assumption.
| |
| assumeFalse | back to summary |
|---|---|
| public static void assumeFalse(boolean assumption, Supplier<@Nullable String> messageSupplier) throws TestAbortedException Validate the given assumption.
| |
| assumeFalse | back to summary |
|---|---|
| public static void assumeFalse(boolean assumption, @Nullable String message) throws TestAbortedException Validate the given assumption.
| |
| assumeFalse | back to summary |
|---|---|
| public static void assumeFalse(BooleanSupplier assumptionSupplier, Supplier<@Nullable String> messageSupplier) throws TestAbortedException Validate the given assumption.
| |
| assumeTrue | back to summary |
|---|---|
| public static void assumeTrue(boolean assumption) throws TestAbortedException Validate the given assumption.
| |
| assumeTrue | back to summary |
|---|---|
| public static void assumeTrue(BooleanSupplier assumptionSupplier) throws TestAbortedException Validate the given assumption.
| |
| assumeTrue | back to summary |
|---|---|
| public static void assumeTrue(BooleanSupplier assumptionSupplier, @Nullable String message) throws TestAbortedException Validate the given assumption.
| |
| assumeTrue | back to summary |
|---|---|
| public static void assumeTrue(boolean assumption, Supplier<@Nullable String> messageSupplier) throws TestAbortedException Validate the given assumption.
| |
| assumeTrue | back to summary |
|---|---|
| public static void assumeTrue(boolean assumption, @Nullable String message) throws TestAbortedException Validate the given assumption.
| |
| assumeTrue | back to summary |
|---|---|
| public static void assumeTrue(BooleanSupplier assumptionSupplier, Supplier<@Nullable String> messageSupplier) throws TestAbortedException Validate the given assumption.
| |
| assumingThat | back to summary |
|---|---|
| public static void assumingThat(BooleanSupplier assumptionSupplier, Executable executable) Execute the supplied 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
| |
| assumingThat | back to summary |
|---|---|
| public static void assumingThat(boolean assumption, Executable executable) Execute the supplied 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
| |
| throwAssumptionFailed | back to summary |
|---|---|
private static void throwAssumptionFailed(@Nullable String message)
| |