org.junit.rules
Class Timeout
java.lang.Object
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)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Timeout
public Timeout(int millis)
- Parameters:
millis
- the millisecond timeout
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 modifiedmethod
- The method to be runtarget
- 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.