public class

Timeout

extends Object
implements MethodRule
java.lang.Object
   ↳ org.junit.rules.Timeout

Class Overview

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 (;;) {
 		}
 	}
 }
 

Summary

Public Constructors
Timeout(int millis)
Public Methods
Statement apply(Statement base, FrameworkMethod method, Object target)
Modifies the method-running Statement to implement an additional test-running rule.
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.junit.rules.MethodRule

Public Constructors

public Timeout (int millis)

Parameters
millis the millisecond timeout

Public Methods

public Statement apply (Statement base, FrameworkMethod method, Object target)

Modifies the method-running Statement to implement an additional test-running rule.

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.