|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.junit.Assume
public class 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. The default JUnit runner treats tests with failing assumptions as ignored. Custom runners may behave differently. For example:
// only provides information if database is reachable. \@Test public void calculateTotalSalary() { DBConnection dbc = Database.connect(); assumeNotNull(dbc); // ... }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(...);
Constructor Summary | |
---|---|
Assume()
|
Method Summary | ||
---|---|---|
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 |
assumeNoException(String message,
Throwable t)
Attempts to halt the test and ignore it if Throwable t is
not null . |
|
static void |
assumeNoException(Throwable t)
Use to assume that an operation completes normally. |
|
static void |
assumeNotNull(Object... objects)
If called with one or more null elements in objects , the test will halt and be ignored. |
|
static
|
assumeThat(String message,
T actual,
Matcher<T> matcher)
Call to assume that actual satisfies the condition specified by matcher . |
|
static
|
assumeThat(T actual,
Matcher<T> matcher)
Call to assume that actual satisfies the condition specified by matcher . |
|
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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Assume()
Method Detail |
---|
public static void assumeTrue(boolean b)
false
, the test will halt and be ignored.
public static void assumeFalse(boolean b)
assumeTrue(boolean)
.
public static void assumeTrue(String message, 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
.message
- A message to pass to AssumptionViolatedException
.public static void assumeFalse(String message, boolean b)
assumeTrue(String, boolean)
.
public static void assumeNotNull(Object... objects)
objects
, the test will halt and be ignored.
public static <T> void assumeThat(T actual, Matcher<T> matcher)
actual
satisfies the condition specified by matcher
.
If not, the test halts and is ignored.
Example:
: assumeThat(1, is(1)); // passes foo(); // will execute assumeThat(0, is(1)); // assumption failure! test halts int x = 1 / 0; // will never execute
T
- the static type accepted by the matcher (this can flag obvious compile-time problems such as assumeThat(1, is("a"))
actual
- the computed value being comparedmatcher
- an expression, built of Matcher
s, specifying allowed valuesCoreMatchers
,
JUnitMatchers
public static <T> void assumeThat(String message, T actual, Matcher<T> matcher)
actual
satisfies the condition specified by matcher
.
If not, the test halts and is ignored.
Example:
: assumeThat(1, is(1)); // passes foo(); // will execute assumeThat(0, is(1)); // assumption failure! test halts int x = 1 / 0; // will never execute
T
- the static type accepted by the matcher (this can flag obvious compile-time problems such as assumeThat(1, is("a"))
actual
- the computed value being comparedmatcher
- an expression, built of Matcher
s, specifying allowed valuesCoreMatchers
,
JUnitMatchers
public static void assumeNoException(Throwable t)
t
is 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); } // ... }
t
- if non-null, the offending exceptionpublic static void assumeNoException(String message, Throwable t)
t
is
not null
. Similar to assumeNoException(Throwable)
,
but provides an additional message that can explain the details
concerning the assumption.
t
- if non-null, the offending exceptionmessage
- Additional message to pass to AssumptionViolatedException
.assumeNoException(Throwable)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |