Package org.junit
Class Assume
java.lang.Object
org.junit.Assume
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(...);
- Since:
- 4.4
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidassumeFalse(boolean b) The inverse ofassumeTrue(boolean).static voidassumeFalse(String message, boolean b) The inverse ofassumeTrue(String, boolean).static voidassumeNoException(String message, Throwable e) Attempts to halt the test and ignore it if Throwableeis notnull.static voidUse to assume that an operation completes normally.static voidassumeNotNull(Object... objects) If called with anullarray or one or morenullelements inobjects, the test will halt and be ignored.static voidassumeTrue(boolean b) If called with an expression evaluating tofalse, the test will halt and be ignored.static voidassumeTrue(String message, boolean b) If called with an expression evaluating tofalse, the test will halt and be ignored.
-
Constructor Details
-
Assume
Deprecated.since 4.13.Do not instantiate.
-
-
Method Details
-
assumeTrue
public static void assumeTrue(boolean b) If called with an expression evaluating tofalse, the test will halt and be ignored. -
assumeFalse
public static void assumeFalse(boolean b) The inverse ofassumeTrue(boolean). -
assumeTrue
If called with an expression evaluating tofalse, the test will halt and be ignored.- Parameters:
b- Iffalse, the method will attempt to stop the test and ignore it by throwingAssumptionViolatedException.message- A message to pass toAssumptionViolatedException.
-
assumeFalse
The inverse ofassumeTrue(String, boolean). -
assumeNotNull
If called with anullarray or one or morenullelements inobjects, the test will halt and be ignored. -
assumeNoException
Use to assume that an operation completes normally. Ifeis non-null, the test will halt and be ignored.For example:
\@Test public void parseDataFile() { DataFile file; try { file = DataFile.open("sampledata.txt"); } catch (IOException e) { // stop test and ignore if data can't be opened assumeNoException(e); } // ... }- Parameters:
e- if non-null, the offending exception
-
assumeNoException
Attempts to halt the test and ignore it if Throwableeis notnull. Similar toassumeNoException(Throwable), but provides an additional message that can explain the details concerning the assumption.- Parameters:
e- if non-null, the offending exceptionmessage- Additional message to pass toAssumptionViolatedException.- See Also:
-