程序包 org.junit.rules
类 RuleChain
- java.lang.Object
- org.junit.rules.RuleChain
- 所有已实现的接口:
TestRule
public class RuleChain extends Object implements TestRule
The RuleChain rule allows ordering of TestRules. You create aRuleChain
withouterRule(TestRule)
and subsequent calls ofaround(TestRule)
:public static class UseRuleChain { @Rule public RuleChain chain= RuleChain .outerRule(new LoggingRule("outer rule") .around(new LoggingRule("middle rule") .around(new LoggingRule("inner rule"); @Test public void example() { assertTrue(true); } }
writes the logstarting outer rule starting middle rule starting inner rule finished inner rule finished middle rule finished outer rule
- 从以下版本开始:
- 4.10
方法概要
所有方法 静态方法 实例方法 具体方法 修饰符和类型 方法 说明 Statement
apply(Statement base, Description description)
Modifies the method-runningStatement
to implement this test-running rule.RuleChain
around(TestRule enclosedRule)
Create a newRuleChain
, which encloses thenextRule
with the rules of the currentRuleChain
.static RuleChain
emptyRuleChain()
Returns aRuleChain
without aTestRule
.static RuleChain
outerRule(TestRule outerRule)
Returns aRuleChain
with a singleTestRule
.
方法详细资料
emptyRuleChain
public static RuleChain emptyRuleChain()
- 返回:
- a
RuleChain
without aTestRule
.
outerRule
public static RuleChain outerRule(TestRule outerRule)
- 参数:
outerRule
- the outer rule of theRuleChain
.- 返回:
- a
RuleChain
with a singleTestRule
.
around
public RuleChain around(TestRule enclosedRule)
Create a newRuleChain
, which encloses thenextRule
with the rules of the currentRuleChain
.- 参数:
enclosedRule
- the rule to enclose.- 返回:
- a new
RuleChain
.
apply
public Statement apply(Statement base, Description description)
Modifies the method-runningStatement
to implement this test-running rule.- 指定者:
apply
在接口中TestRule
- 参数:
base
- TheStatement
to be modifieddescription
- ADescription
of the test implemented inbase
- 返回:
- a new statement, which may be the same as
base
, a wrapper aroundbase
, or a completely new Statement.