title: @Before method in TestRule is not called
body: <p>I implemented a <em>JUnit 4</em> <code>TestRule</code> (extending an <code>ExternalResource</code>), and injected it as a <code>@ClassRule</code> in my test class: I want to initialize a resource once for all in every test of this class, and tear it down eventually.</p>
  
  <p>My issue is that my <code>@Before</code> and <code>@After</code> rule-methods are not called at all before/after my <code>@Test</code> method: any idea why this is happening?</p>
  
  <p>Minimal compilable example:</p>
  
  <pre><code>package com.acme.test;
  
  import static org.junit.Assert.assertNull;
  import org.junit.ClassRule;
  import org.junit.Test;
  import org.junit.rules.ExternalResource;
  
  class Coffee {
      public void throwAway() {}
  }
  
  class CoffeeMachine extends ExternalResource {
      Coffee whatElse;    
      @Override protected void before() throws Throwable {
          whatElse = new Coffee();
      }
  
      @Override protected void after() {
          whatElse.throwAway();
      }
  
      public Coffee gimmieCoffee() { return whatElse; }
  }
  
  public class CoffeeTester {
      @ClassRule public static CoffeeMachine CM = new CoffeeMachine();
  
      @Test public void drinkACoffee() {
          Coffee c = CM.gimmieCoffee();
          assertNull(c);  // ---&gt; Coffee is null!!                       (fuuuuuuuuuu...)
      }
  }
  </code></pre>
  
  <p>Is there something I am misunderstanding here? Note that the same happens with a non-static <code>@Rule</code>.</p>
  
  <p>I am using <strong>JUnit 4.11</strong>.</p>
  
  <p>Thank you very much for any hint.</p>