KentBeck/junit — Issue #350: @Rule should not require MethodRule in 4.10, regression?
Author: Art-B
Created: 2011-10-21 18:39:09+00:00
State: open

I believe this is a regression. I was investigating an issue I was having where a test would fail on a build server but pass locally when I realised I was using 4.9 locally and 4.10 on the server. It was complaining the my @Rule field "must implement MethodRule" and I started to suspect a regression. I would this strange as that field was implementing TestRule. As such I decided to test this using the example code from http://kentbeck.github.com/junit/javadoc/latest/org/junit/rules/RuleChain.html

Which I updated to be compilable (the example is missing some parentheses for example, could someone update that as well with this fragment?) which gave me the same error. So either there is a regression, or the example is wrong, or I am stupid and missing something: those are all equally possible.

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
import static org.junit.Assert.assertTrue;

public class UseRuleChain {
@Rule
public TestRule chain= RuleChain
.outerRule(new LoggingRule("outer rule"))
.around(new LoggingRule("middle rule"))
.around(new LoggingRule("inner rule"));

@Test
public void example() {
assertTrue(true);
}

static class LoggingRule implements TestRule{
String s;
public LoggingRule( String s ){
this.s = s;
}

@Override
public Statement apply( Statement arg0, Description arg1 ){
System.out.println( this.s );
return arg0;
}
}
}