5

As per the answer to the similar question found here I'm posting on meta to ask how my question:

Why/how does JUnit pass tests with compiler errors?

is a duplicate of this question:

Java: Unresolved compilation problem.

To repeat my edit:

  • The question I'm supposed to be duplicating asks in the first line:

What are the possible causes of a "java.lang.Error: Unresolved compilation problem"?

  • The title of my question states I'm asking:

Why/how does JUnit pass tests with compiler errors?

As in how can code which shouldn't compile be run by JUnit without causing errors? I fully understand the causes of the Unresolved Compilation Error, it's the obvious unresolved compilation error in my code. What I don't understand is how the error doesn't always occur (it only occurs when I specifically call an unimplemented method) and how the tests pass?!

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...

1 Answer 1

4

It appears that the other question does explain your problem. It's saying that when a class fails to implement an interface method, the Java compiler does not reject the code but instead emits bytecode for the method that will raise the runtime error seen. This explains why JUnit is able to run the tests and why the test passes if you don't call methodB - the runtime error does not get raised.

2
  • Maybe I'm misunderstanding the concept behind a stackoverflow duplicate question, but afaict it seems that although the issues are related and an answer to my question can be derived from the top voted answer in the other, the questions themselves are in no way duplicate! On the other hand, your answer here does answer my original question, so if you want to post it there as an answer, I'd mark it accepted.
    – mallardz
    Commented May 18, 2014 at 14:10
  • 1
    I'm finding myself in a similar situation. My question was marked as a duplicate of another question. Now, if I already had the answer to the other question, it would have given me the answer to my question - but it doesn't work in reverse; looking for the answer to my question did not lead me to the other question, since you needed to know the answer to my question to even ask the other question! (my question is here: stackoverflow.com/questions/25467321/…)
    – afeldspar
    Commented Aug 24, 2014 at 12:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .