程序包 org.junit
类 Assume
- java.lang.Object
- org.junit.Assume
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(...);
- 从以下版本开始:
- 4.4
- 另请参阅:
- Theories
构造器概要
构造器 构造器 说明 Assume()
方法概要
所有方法 静态方法 具体方法 修饰符和类型 方法 说明 static void
assumeFalse(boolean b)
The inverse ofassumeTrue(boolean)
.static void
assumeFalse(String message, boolean b)
The inverse ofassumeTrue(String, boolean)
.static void
assumeNoException(String message, Throwable e)
Attempts to halt the test and ignore it if Throwablee
is notnull
.static void
assumeNoException(Throwable e)
Use to assume that an operation completes normally.static void
assumeNotNull(Object... objects)
If called with one or more null elements inobjects
, the test will halt and be ignored.static <T> void
assumeThat(String message, T actual, Matcher<T> matcher)
Call to assume thatactual
satisfies the condition specified bymatcher
.static <T> void
assumeThat(T actual, Matcher<T> matcher)
Call to assume thatactual
satisfies the condition specified bymatcher
.static void
assumeTrue(boolean b)
If called with an expression evaluating tofalse
, the test will halt and be ignored.static void
assumeTrue(String message, boolean b)
If called with an expression evaluating tofalse
, the test will halt and be ignored.
构造器详细资料
Assume
public Assume()
方法详细资料
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
public static void assumeTrue(String message, boolean b)
If called with an expression evaluating tofalse
, the test will halt and be ignored.- 参数:
b
- Iffalse
, the method will attempt to stop the test and ignore it by throwingAssumptionViolatedException
.message
- A message to pass toAssumptionViolatedException
.
assumeFalse
public static void assumeFalse(String message, boolean b)
The inverse ofassumeTrue(String, boolean)
.
assumeNotNull
public static void assumeNotNull(Object... objects)
If called with one or more null elements inobjects
, the test will halt and be ignored.
assumeThat
public static <T> void assumeThat(T actual, Matcher<T> matcher)
Call to assume thatactual
satisfies the condition specified bymatcher
. 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 asassumeThat(1, is("a"))
- 参数:
actual
- the computed value being comparedmatcher
- an expression, built ofMatcher
s, specifying allowed values- 另请参阅:
CoreMatchers
,JUnitMatchers
assumeThat
public static <T> void assumeThat(String message, T actual, Matcher<T> matcher)
Call to assume thatactual
satisfies the condition specified bymatcher
. If not, the test halts and is ignored. Example:: assumeThat("alwaysPasses", 1, is(1)); // passes foo(); // will execute assumeThat("alwaysFails", 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 asassumeThat(1, is("a"))
- 参数:
actual
- the computed value being comparedmatcher
- an expression, built ofMatcher
s, specifying allowed values- 另请参阅:
CoreMatchers
,JUnitMatchers
assumeNoException
public static void assumeNoException(Throwable e)
Use to assume that an operation completes normally. Ife
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); } // ... }
- 参数:
e
- if non-null, the offending exception
assumeNoException
public static void assumeNoException(String message, Throwable e)
Attempts to halt the test and ignore it if Throwablee
is notnull
. Similar toassumeNoException(Throwable)
, but provides an additional message that can explain the details concerning the assumption.- 参数:
e
- if non-null, the offending exceptionmessage
- Additional message to pass toAssumptionViolatedException
.- 另请参阅:
assumeNoException(Throwable)