5 Replies Latest reply on May 14, 2008 2:57 AM by 796254

    JUnit problem!!!!!

    807591
      hi guys
      i m new to JUnit. I m running my test program. But there is error message i could not find the solution. im using junit 4.3 and i already change CLASSPATH.
      but still have error. Plz help me !!!

      thx in advance.
      import org.junit.*;
      import static org.junit.Assert.*;
      //import java.lang.annotation.Annotation;
      
          public class ShoppingCartTest
          {
         
               @Before
                public void beforeShoppingCartTest()
                {
               
                  }
      
              @Test
              public void beforeTest ()
              {
                      assertTrue(true);
              }
      
              @After
              public void afterShoppingCartTest (){
                 System.out.println("Afterwards");
               }
          }
      errors message:
           D:\w10_testing\tutorial\ShoppingCartTest.java:22: incompatible types
      found   : Test
      required: java.lang.annotation.Annotation
              @Test
               ^
      1 error
        • 1. Re: JUnit problem!!!!!
          796254
          JAVA-rookie wrote:
          hi guys
          i m new to JUnit. I m running my test program. But there is error message i could not find the solution. im using junit 4.3 and i already change CLASSPATH.
          You did it wrong.
          but still have error. Plz help me !!!
          Learn how to set CLASSPATH correctly.

          If the JUnit JAR was in your CLASSPATH, you wouldn't get that error.

          %
          • 2. Re: JUnit problem!!!!!
            807591
            but i compile the tutorial example. same import package. almost same there is no error
            import org.junit.*;
            import static org.junit.Assert.*;
            
                public class GreeterTest
                {
                        Greeter greeter = new Greeter("bob");
                        String response ;
            
            
                     @Before
                      public void somename (){
                            response = greeter.greet();
                    }
            
                   @Test
                    public void beforeTest (){
                       System.out.println("before the main test");
                     }
            
            /*        @Test
                    public void testGreet()
                    {
                       assertTrue(response.equals("Hello bob"));
                    }
            
                    @Test
                    public void anotherTest (){
                       System.out.println("another test");
                     }
            */
            
            
                    @After
                    public void afterwards (){
                       System.out.println("Afterwards");
                     }
                }
            by the way
            i change to@org.junit.Test instead of @Test. its running for my previous code. Could u explain this for me plz?

            Edited by: JAVA-rookie on May 13, 2008 6:53 PM
            • 3. Re: JUnit problem!!!!!
              807591
              I googled this:
              "incompatible types" junit "@test" annotation
              and found this that might be of help:
              http://forum.java.sun.com/thread.jspa?threadID=5092503&messageID=9319086
              • 4. Re: JUnit problem!!!!!
                807591
                i have checked this thread before i post my thread.but i m confusing about that there r 2 codes almost same. one can run. one have error message. thx for reply
                • 5. Re: JUnit problem!!!!!
                  796254
                  read the error message, understand it and fix it.

                  junit 4 annotations work fine if you know what you're doing.

                  %