blob: 85ce6d6fa49e9353fdec17d6a00d7d3de10ed995 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
/**
*
*/
package org.junit.rules;
import org.junit.internal.runners.statements.FailOnTimeout;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
/**
* The Timeout Rule applies the same timeout to all test methods in a class:
*
* <pre>
* 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 (;;) {
* }
* }
* }
* </pre>
*/
public class Timeout implements TestRule {
private final int fMillis;
/**
* @param millis the millisecond timeout
*/
public Timeout(int millis) {
fMillis= millis;
}
public Statement apply(Statement base, Description description) {
return new FailOnTimeout(base, fMillis);
}
}
|