title: Why/how does JUnit pass tests with compiler errors?
body: <p>I've just started learning about TDD and am trying to write a simple project that way.</p>
  
  <p>I'm using Eclipse and JUnit, and every time I make a change I run all the tests in the relevant package.</p>
  
  <p>But then I'm very surprised to see in the package explorer that one of my test cases has a big red cross indicating a compiler problem... Annoyed I figured that I got my eclipse shortcuts mixed up and haven't been running all the tests, as they are all passing.</p>
  
  <p>But when I start fiddling about, I realise that it seems Eclipse + JUnit will run and pass tests even if there are compiler errors...</p>
  
  <p>The JUnit test case:</p>
  
  <pre><code>import static org.junit.Assert.*;
  
  import org.junit.Before;
  import org.junit.Test;
  
  public class ATestCase {
  
      private Command command;
      private Invoker invoker;
  
      @Before
      public void setUp() throws Exception {
  
          command = new Command() {
              public void methodA(){};
              //haven't implemented methodB()
          };
  
          invoker = new Invoker(command);
  
      }
  
      @Test
      public void test(){
          invoker.invoke();
      }
  }
  
  interface Command{
      void methodA();
      void methodB();
  }
  </code></pre>
  
  <p>The Invoker class:</p>
  
  <pre><code>class Invoker{
  
      private Command command;
  
      public Invoker(Command command) {
          this.command = command;
          //if I invoke methodB() I get UnresolvedCompilationError
      }
  
      public void invoke(){
          command.methodA();
          //only if I call methodB here
          //do I get Unresolved compilation problem
  //      command.methodB();
      }
  }
  </code></pre>
  
  <p>The command object I create in setUp in the test case only implements one of the interface's methods. This of course causes a compilation error warning in Eclipse.</p>
  
  <p>However unless I actually call that method in the test case, the test passes.
  If I do call the method, then the test fails with 'unresolved compilation error'.</p>
  
  <p><img src="https://i.stack.imgur.com/V3Ios.png" alt="enter image description here"></p>
  
  <p>Can anyone explain to me what exactly is going on?</p>
  
  <p>******EDIT******</p>
  
  <p>I'm not sure why this was closed as a duplicate.</p>
  
  <p>Apparently I'm supposed to edit this question to make the difference clear:</p>
  
  <ul>
  <li>Well the question I'm supposed to be duplicating asks in the first line:</li>
  </ul>
  
  <blockquote>
    <p>What are the possible causes of a "java.lang.Error: Unresolved
    compilation problem"?</p>
  </blockquote>
  
  <ul>
  <li>The title of my question states I'm asking: </li>
  </ul>
  
  <blockquote>
    <p>Why/how does JUnit pass tests with compiler errors?</p>
  </blockquote>
  
  <p>As in how can code which <strong>shouldn't</strong> compile be run by JUnit <strong>without</strong> causing errors?
  I fully understand the causes of the <code>Unresolved Compilation Error</code>, it's the <strong>obvious unresolved compilation error</strong> in my code. What I don't understand is <strong>how</strong> the error <strong>doesn't</strong> always occur (it only occurs when I specifically call an unimplemented method) and how the tests pass?! </p>
  
  <p>It may be that these issues are related, but unless there is a specific answer explaining how they are related I fail to see how they are in any way duplicate questions...</p>