public class Assume extends Object
A set of methods useful for stating assumptions about the conditions in which a test is meaningful. A failed assumption does not mean the code is broken, but that the test provides no useful information. Assume basically means "don't run this test if these conditions don't apply". The default JUnit runner skips tests with failing assumptions. Custom runners may behave differently.
A good example of using assumptions is in Theories where they are needed to exclude certain datapoints that aren't suitable or allowed for a certain test case. Failed assumptions are usually not logged, because there may be many tests that don't apply to certain configurations.
These methods can be used directly: Assume.assumeTrue(...), however, they read better if they are referenced through static import:
import static org.junit.Assume.*; ... assumeTrue(...);
Modifier and Type | Method and Description |
---|---|
static void |
assumeFalse(boolean b)
The inverse of
assumeTrue(boolean) . |
static void |
assumeFalse(String message,
boolean b)
The inverse of
assumeTrue(String, boolean) . |
static void |
assumeTrue(boolean b)
If called with an expression evaluating to
false , the test will
halt and be ignored. |
static void |
assumeTrue(String message,
boolean b)
If called with an expression evaluating to
false , the test will
halt and be ignored. |
public static void assumeFalse(boolean b)
assumeTrue(boolean)
.public static void assumeFalse(String message, boolean b)
assumeTrue(String, boolean)
.public static void assumeTrue(boolean b)
false
, the test will
halt and be ignored.b
- If false
, the method will attempt to stop the test
and ignore it by throwing AssumptionViolatedException
.public static void assumeTrue(String message, boolean b)
false
, the test will
halt and be ignored.message
- A message to pass to AssumptionViolatedException
.b
- If false
, the method will attempt to stop the test
and ignore it by throwing AssumptionViolatedException
.