title: How to test a java interface?
body: <p>I have an interface and a class that implements that interface and overrides it's methods:</p>
  
  <pre><code>public interface Intr {
  public int method1();
  public int method2();
  }
  
  
  public class example implements Intr{
  @override
  public int method1()
  {
  //stmts
  }
  @override
  public int method2(){
  //stmts
  }
  } 
  </code></pre>
  
  <p>i want to create a JUnit test to test that interface <strong>without implementing the class on my test</strong>, i used a code like :</p>
  
  <pre><code>public class TIntr {
  
      private Intr interface;
  
      @BeforeClass
      public static void setUpBeforeClass() throws Exception {
      }
  
      @AfterClass
      public static void tearDownAfterClass() throws Exception {
      }
  
      @Test
      public Object testMethod1() {
          try{
          int result = interface.method1();
          assertEquals(something, result);
          }catch(Exception e){
          fail("Test Failed!!");
          }
  
  
          @Test
      public Object testMethod1() {
          try{
          int result = interface.method2();
          assertEquals(something, result);
          }catch(Exception e){
          fail("Test Failed!!");
          }
  }
  </code></pre>
  
  <p>but the test always fails as the execution of the methods always generate null values as i didn't create instance from the class, only a variable from the type interface.</p>