程序包 org.junit.rules

类 RuleChain

  • 所有已实现的接口:
    TestRule

    public class RuleChain
    extends Object
    implements TestRule
    The RuleChain rule allows ordering of TestRules. You create a RuleChain with outerRule(TestRule) and subsequent calls of around(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 log
     starting outer rule
     starting middle rule
     starting inner rule
     finished inner rule
     finished middle rule
     finished outer rule
     
    从以下版本开始:
    4.10
    • 方法详细资料

      • outerRule

        public static RuleChain outerRule​(TestRule outerRule)
        Returns a RuleChain with a single TestRule. This method is the usual starting point of a RuleChain.
        参数:
        outerRule - the outer rule of the RuleChain.
        返回:
        a RuleChain with a single TestRule.
      • around

        public RuleChain around​(TestRule enclosedRule)
        Create a new RuleChain, which encloses the nextRule with the rules of the current RuleChain.
        参数:
        enclosedRule - the rule to enclose.
        返回:
        a new RuleChain.
      • apply

        public Statement apply​(Statement base,
                               Description description)
        Modifies the method-running Statement to implement this test-running rule.
        指定者:
        apply 在接口中 TestRule
        参数:
        base - The Statement to be modified
        description - A Description of the test implemented in base
        返回:
        a new statement, which may be the same as base, a wrapper around base, or a completely new Statement.