Re: JUnit 4 Life-Cycle (Intercepts)

"Stefan Birkner [email protected] [junit]" <[email protected]> Thu, 3 Jul 2014 22:18:39 +0200
Newsgroups gmane.comp.java.junit.user
Message-ID <CAHhYVJ6R9sHN8AM71zTs55R2L5DuvA=vHh_dBOeY-mretL9G-A@mail.gmail.com>
You can remove the @Rule annotation and use the rule explicitly in the test
sub-classes

@Rule
public TestRule theFinalChain = chain.around(someOtherRule());

or even create a class for the RuleChain

public class YourSomethingRule implements TestRule {
   private final TestRule chain = RuleChain.outerRule(...

   public Statement apply(Statement base, Description description) {
     chain.apply(base, description);
   }
}

and use it in the sub-classes

@Rule
public TestRule chain = RuleChain.outerRule(new YourRule()).around(...

stefan



2014-07-03 4:48 GMT+02:00 [email protected] [junit] <
[email protected]>:

>
>
> Let me try a more concrete question.  The following RuleChain is contained
> in a base class and we want to append additional rules as required in
> concrete test sub-classes.
>
> Any suggestions on how to append a rule to a RuleChain???
>
>
> /** This chain of rules is executed in coded order. */
> @Rule
> public TestRule chain = RuleChain
> .outerRule(
> new JptStep000InitializeTestIndicatorRequiredRule(
> setupResourceTM()))
> .around(new JptStep010InitializeInputOutputDirectoryRule())
> .around(new JptStep020InitializeCdiBeanManagerRule())
> .around(new JptStep030InitializeCdiScopesRule())
> .around(new JptStep040InitializeCdiAnnotationsOnTestClassRule(this))
> .around(new JptStep050InitializePluginConfigurationRule(
> setupResourceTM()))
> .around(new JptStep060VerifyRequiredPluginsRule())
> .around(new JptStep070InitializeEmbeddedDatabaseRule())
> .around(new JptStepOptionalInitializeResourcesRule())
> .around(new JptStepOptionalDisplayUnexpectedStackTraceRule())
> .around(new JptStepLastDisplayBeginAndAfterRule());
>
> _Marvin
>
>  
>