Assume (JUnit API)

Junit


org.junit Class Assume

java.lang.Object
  extended by 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. 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(...);
 


构造器摘要
Assume()
           
 
方法摘要
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
<T> void
assumeThat(T actual, org.hamcrest.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.  
类方法继承: java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

构造器详细信息

Assume

public Assume()
方法详细信息

assumeTrue

public static void assumeTrue(boolean b)
If called with an expression evaluating to false, the test will halt and be ignored.

参数:
b -

assumeNotNull

public static void assumeNotNull(Object... objects)
If called with one or more null elements in objects, the test will halt and be ignored.

参数:
objects -

assumeThat

public static <T> void assumeThat(T actual,
                                  org.hamcrest.Matcher<T> matcher)
Call to assume that 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
 

Type Parameters:
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 compared
matcher - an expression, built of Matchers, specifying allowed values
另请参见:
CoreMatchers, JUnitMatchers

assumeNoException

public static void assumeNoException(Throwable t)
Use to assume that an operation completes normally. If 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 exception