| 
| JUnit 4 Tests With Compile Errors Do Not Run [message #213908] | Tue, 05 June 2007 13:22  |  | 
| Eclipse User  |  |  |  |  | Originally posted by: joeboccanfuso.gmail.com 
 Hi,
 
 I have noticed that JUnit 4 tests (i.e. test methods annotated with
 @Test) that contain compile errors are not executed when the test suite
 is launched in Eclipse (i.e those that compile fine execute and ones
 with compile errors are skipped).  However, if the tests were written
 with JUnit 3, then those methods with compile errors are executed when
 the test suite is launched in Eclipse.  They result in error and throw
 java.lang.Error with "Unresolved compilation problems:...".  I have
 included examples of each below.
 
 The behaviour in JUnit 3 is what I am after, but I am not sure if that
 is possible with JUnit 4.  I suspect that Eclipse is doing a partial
 compile of the the .java file containing the tests, stubbing those
 methods with compile errors with a throw new(java.lang.Error(...));, and
 removing the @Test annotation.  I was able to use a decompiler to verify
 the stubbing being done, however I was not able to find a decompiler
 that supported annotations.
 
 Here are the test cases.  Running MyJUnit3Test in the Eclipse IDE
 produces a red bar with 2 tests run and 1 error.  Running MyJUnit4Test
 in the Eclipse IDE produces a green bar with 1 test run and zero errors
 or failures.
 
 Is there a way to get the JUnit 3 result with JUnit 4?
 
 -----
 import junit.framework.TestCase;
 
 public class MyJUnit3Test extends TestCase
 {
 
 public void test1()
 {
 syntax error
 }
 
 public void test2()
 {
 
 }
 }
 -----
 import org.junit.Test;
 
 public class MyJUnit4Test
 {
 @Test
 public void test1()
 {
 syntax error
 }
 
 @Test
 public void test2()
 {
 
 }
 
 }
 -----
 
 Thanks in advanced,
 
 Ciao,
 
 Joe
 |  |  |  | 
| 
| Re: JUnit 4 Tests With Compile Errors Do Not Run [message #213932 is a reply to message #213908] | Tue, 05 June 2007 14:32  |  | 
| Eclipse User  |  |  |  |  | Joe Boccanfuso a écrit : > The behaviour in JUnit 3 is what I am after, but I am not sure if that
 > is possible with JUnit 4.  I suspect that Eclipse is doing a partial
 > compile of the the .java file containing the tests, stubbing those
 > methods with compile errors with a throw new(java.lang.Error(...));, and
 > removing the @Test annotation.  I was able to use a decompiler to verify
 >  the stubbing being done, however I was not able to find a decompiler
 > that supported annotations.
 You should use the Eclipse disassembler :-).
 Here is what I get:
 // Compiled from X.java (version 1.5 : 49.0, super bit)
 public class X {
 Constant pool:
 constant #1 class: #2 X
 constant #2 utf8: "X"
 constant #3 class: #4 java/lang/Object
 constant #4 utf8: "java/lang/Object"
 constant #5 utf8: "<init>"
 constant #6 utf8: "()V"
 constant #7 utf8: "Code"
 constant #8 method_ref: #3.#9 java/lang/Object.<init> ()V
 constant #9 name_and_type: #5.#6 <init> ()V
 constant #10 utf8: "LineNumberTable"
 constant #11 utf8: "LocalVariableTable"
 constant #12 utf8: "this"
 constant #13 utf8: "LX;"
 constant #14 utf8: "test1"
 constant #15 class: #16 java/lang/Error
 constant #16 utf8: "java/lang/Error"
 constant #17 string: #18 "Unresolved compilation problem:
 \n\tSyntax error, insert ";" to complete BlockStatements\n"
 constant #18 utf8: "Unresolved compilation problem: \n\tSyntax
 error, insert ";" to complete BlockStatements\n"
 constant #19 method_ref: #15.#20 java/lang/Error.<init>
 (Ljava/lang/String;)V
 constant #20 name_and_type: #5.#21 <init> (Ljava/lang/String;)V
 constant #21 utf8: "(Ljava/lang/String;)V"
 constant #22 utf8: "test2"
 constant #23 utf8: "RuntimeInvisibleAnnotations"
 constant #24 utf8: "LTest;"
 constant #25 utf8: "SourceFile"
 constant #26 utf8: "X.java"
 
 // Method descriptor #6 ()V
 // Stack: 1, Locals: 1
 public X();
 0  aload_0 [this]
 1  invokespecial java.lang.Object() [8]
 4  return
 Line numbers:
 [pc: 0, line: 3]
 Local variable table:
 [pc: 0, pc: 5] local: this index: 0 type: X
 
 // Method descriptor #6 ()V
 // Stack: 3, Locals: 1
 public void test1();
 0  new java.lang.Error [15]
 3  dup
 4  ldc <String "Unresolved compilation problem: \n\tSyntax error,
 insert ";" to complete BlockStatements\n"> [17]
 6  invokespecial java.lang.Error(java.lang.String) [19]
 9  athrow
 Line numbers:
 [pc: 0, line: 6]
 Local variable table:
 [pc: 0, pc: 10] local: this index: 0 type: X
 
 // Method descriptor #6 ()V
 // Stack: 0, Locals: 1
 public void test2();
 0  return
 Line numbers:
 [pc: 0, line: 12]
 Local variable table:
 [pc: 0, pc: 1] local: this index: 0 type: X
 RuntimeInvisibleAnnotations:
 #24 @Test(
 )
 }
 
 As you can see there is no annotation for the test1 method. This is the
 problem. We don't preserve annotations for problem methods.
 
 > Is there a way to get the JUnit 3 result with JUnit 4?
 I opened https://bugs.eclipse.org/bugs/show_bug.cgi?id=191090. Please
 add yourself to the CC list.
 --
 Olivier
 |  |  |  | 
Powered by 
FUDForum. Page generated in 0.07665 seconds