| 
 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.junit.rules.Timeout
public class Timeout
The Timeout Rule applies the same timeout to all test methods in a class:
 public static class HasGlobalLongTimeout {
  @Rule
  public Timeout globalTimeout= new Timeout(20);
  @Test
  public void run1() throws InterruptedException {
      Thread.sleep(100);
  }
  @Test
  public void infiniteLoop() {
      while (true) {}
  }
 }
 
 
 Each test is run in a new thread. If the specified timeout elapses before
 the test completes, its execution is interrupted via Thread.interrupt().
 This happens in interruptable I/O and locks, and methods in Object
 and Thread throwing InterruptedException.
 
A specified timeout of 0 will be interpreted as not set, however tests will still launch from separate threads. This can be useful for disabling timeouts in environments where they are dynamically set based on some property.
| Nested Class Summary | |
|---|---|
| static class | Timeout.BuilderBuilder for Timeout. | 
| Constructor Summary | |
|---|---|
|   | Timeout(int millis)Deprecated. | 
|   | Timeout(long timeout,
               TimeUnit timeUnit)Create a Timeoutinstance with the timeout specified
 at the timeUnit of granularity of the providedTimeUnit. | 
| protected  | Timeout(Timeout.Builder builder)Create a Timeoutinstance initialized with values form
 a builder. | 
| Method Summary | |
|---|---|
|  Statement | apply(Statement base,
           Description description)Modifies the method-running Statementto implement this
 test-running rule. | 
| static Timeout.Builder | builder()Returns a new builder for building an instance. | 
| protected  Statement | createFailOnTimeoutStatement(Statement statement)Creates a Statementthat will run the givenstatement, and timeout the operation based
 on the values configured in this rule. | 
| protected  boolean | getLookingForStuckThread()Gets whether this Timeoutwill look for a stuck thread
 when the test times out. | 
| protected  long | getTimeout(TimeUnit unit)Gets the timeout configured for this rule, in the given units. | 
| static Timeout | millis(long millis)Creates a Timeoutthat will timeout a test after the
 given duration, in milliseconds. | 
| static Timeout | seconds(long seconds)Creates a Timeoutthat will timeout a test after the
 given duration, in seconds. | 
| Methods inherited from class java.lang.Object | 
|---|
| clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | 
| Constructor Detail | 
|---|
@Deprecated public Timeout(int millis)
Timeout instance with the timeout specified
 in milliseconds.
 This constructor is deprecated.
 Instead use Timeout(long, java.util.concurrent.TimeUnit),
 millis(long), or seconds(long).
millis - the maximum time in milliseconds to allow the
 test to run before it should timeout
public Timeout(long timeout,
               TimeUnit timeUnit)
Timeout instance with the timeout specified
 at the timeUnit of granularity of the provided TimeUnit.
timeout - the maximum time to allow the test to run
 before it should timeouttimeUnit - the time unit for the timeoutprotected Timeout(Timeout.Builder builder)
Timeout instance initialized with values form
 a builder.
| Method Detail | 
|---|
public static Timeout.Builder builder()
public static Timeout millis(long millis)
Timeout that will timeout a test after the
 given duration, in milliseconds.
public static Timeout seconds(long seconds)
Timeout that will timeout a test after the
 given duration, in seconds.
protected final long getTimeout(TimeUnit unit)
protected final boolean getLookingForStuckThread()
Timeout will look for a stuck thread
 when the test times out.
protected Statement createFailOnTimeoutStatement(Statement statement)
                                          throws Exception
Statement that will run the given
 statement, and timeout the operation based
 on the values configured in this rule. Subclasses
 can override this method for different behavior.
Exception
public Statement apply(Statement base,
                       Description description)
TestRuleStatement to implement this
 test-running rule.
apply in interface TestRulebase - The Statement to be modifieddescription - A Description of the test implemented in base
base,
         a wrapper around base, or a completely new Statement.| 
 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||