I am not very familiar with the rule ordering in JUnit and especially the RuleChain
class. So I had a quick look at this class' documentation. The example code snippet seems to be your solution when being used in a template method sense.
I could imagine that following mechanism will work:
public abstract class BaseTestCase {
@Rule
public final RuleChain ruleChain = createRuleChain();
private RuleChain createRuleChain() {
return appendInnerRules(RuleChain.outerRule(createOuterRule()));
}
protected TestRule createOuterRule() {
return new Timeout(60 * 1000);
}
protected RuleChain appendInnerRules(RuleChain ruleChain) {
return ruleChain; // default behavior
}
}
public final class TestSomeController extends BaseTestCase {
protected RuleChain appendInnerRules(RuleChain ruleChain) {
return ruleChain.around(new RunOnEventDispatchThread());
}
@Test
public void testStuff() { /* ... */ }
}