org.junit.rules
Class Timeout

java.lang.Object
  extended by org.junit.rules.Timeout
All Implemented Interfaces:
MethodRule

public class Timeout
extends Object
implements MethodRule

The Timeout Rule applies the same timeout to all test methods in a class:

 public static class HasGlobalTimeout {
        public static String log;
 
        @Rule
        public MethodRule globalTimeout= new Timeout(20);
 
        @Test
        public void testInfiniteLoop1() {
                log+= "ran1";
                for (;;) {
                }
        }
 
        @Test
        public void testInfiniteLoop2() {
                log+= "ran2";
                for (;;) {
                }
        }
 }
 


Constructor Summary
Timeout(int millis)
           
 
Method Summary
 Statement apply(Statement base, FrameworkMethod method, Object target)
          Modifies the method-running Statement to implement an additional test-running rule.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Timeout

public Timeout(int millis)
Parameters:
millis - the millisecond timeout
Method Detail

apply

public Statement apply(Statement base,
                       FrameworkMethod method,
                       Object target)
Description copied from interface: MethodRule
Modifies the method-running Statement to implement an additional test-running rule.

Specified by:
apply in interface MethodRule
Parameters:
base - The Statement to be modified
method - The method to be run
target - The object on with the method will be run.
Returns:
a new statement, which may be the same as base, a wrapper around base, or a completely new Statement.