title: Best Practice: Testing Interface Contract Compliance?
body: <p>Assume that interface for is defined</p>
  
  <pre><code>interface Foo {
    int getBaz();
    void doBar();
  }
  </code></pre>
  
  <p>Further assume that the contract states that everytime doBar is called baz is incremented. (Ok this is a contrived bit of code but stick with me here)</p>
  
  <p>Now I want to provide a unit test that I can provide to Foo implementers so that they can verify that they meet all the contract conditions.</p>
  
  <pre><code>class FooTest {
    protected Foo fooImpl;
  
    @Test
    public void int testBazIncrement()
    {
      int b = fooImpl getBaz();
      fooImpl.doBar();
      Assert.assertEquals( b+1, fooImpl.getBaz();
    }
  }
  </code></pre>
  
  <p>What are the best practices for making the test available to the implemnters of Foo?  It seems to me that there needs to be a mechanism for them to call the FooTest and provide a Foo or a FooFactory to construct Foo instances.  Furthermore, if there are many tests (think big interface) then I want to put all those tests in one FooTest class.</p>
  
  <p>Are there any best practices for how to implement such tests?</p>