程序包 org.junit.rules
接口 MethodRule
- 所有已知实现类:
TestWatchman
public interface MethodRule
A MethodRule is an alteration in how a test method is run and reported. MultipleMethodRule
s can be applied to a test method. TheStatement
that executes the method is passed to each annotatedRule
in turn, and each may return a substitute or modifiedStatement
, which is passed to the nextRule
, if any. For examples of how this can be useful, see these provided MethodRules, or write your own:ErrorCollector
: collect multiple errors in one test methodExpectedException
: make flexible assertions about thrown exceptionsExternalResource
: start and stop a server, for exampleTemporaryFolder
: create fresh files, and delete after testTestName
: remember the test name for use during the methodTestWatchman
: add logic at events during method executionTimeout
: cause test to fail after a set timeVerifier
: fail test if object state ends up incorrect
MethodRule
has been replaced byTestRule
, which has the added benefit of supporting class rules.- 从以下版本开始:
- 4.7
方法详细资料
apply
Statement apply(Statement base, FrameworkMethod method, Object target)
Modifies the method-runningStatement
to implement an additional test-running rule.- 参数:
base
- TheStatement
to be modifiedmethod
- The method to be runtarget
- The object on which the method will be run.- 返回:
- a new statement, which may be the same as
base
, a wrapper aroundbase
, or a completely new Statement.