title: Testing multiple interface implementations with same tests - JUnit4
body: <p>I want to run the same JUnit tests for different interface implementations. I found a nice solution with the <strong>@Parameter</strong> option:</p>
  
  <pre><code>public class InterfaceTest{
  
    MyInterface interface;
  
    public InterfaceTest(MyInterface interface) {
      this.interface = interface;
    }
  
    @Parameters
    public static Collection&lt;Object[]&gt; getParameters()
    {
      return Arrays.asList(new Object[][] {
        { new GoodInterfaceImpl() },
        { new AnotherInterfaceImpl() }
      });
    }
  }
  </code></pre>
  
  <p>This test would be run twice, first with the <strong>GoodInterfaceImpl</strong> then with the <strong>AnotherInterfaceImpl</strong> class. But the problem is I need for most of the testcases a new object. A simplified example:</p>
  
  <pre><code>@Test
  public void isEmptyTest(){
     assertTrue(interface.isEmpty());
  }
  
  @Test
  public void insertTest(){
     interface.insert(new Object());
     assertFalse(interface.isEmpty());
  }
  </code></pre>
  
  <p>If the <strong>isEmptyTest</strong> is run after the <strong>insertTest</strong> it fails.</p>
  
  <p>Is there an option to run automatically each testcase with a new instance of an implementation?</p>
  
  <p>BTW: Implementing a <em>clear()</em> or <em>reset()</em>-method for the interface is not really an options since I would not need it in productive code.</p>