javac won't accept @test

View: New views
2 Messages — Rating Filter:   Alert me  

javac won't accept @test

by Josheva :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi.  I've successfully used JUnit 3 before, but I'm having trouble with JUnit 4.  Before I get into this, I'm using Windows Vista 64-bit, Java 1.6.0_16, and JUnit 4.5.

Simply put, javac won't accept the @Test flags that, I understand, are supposed to prefix every test method.  To illustrate my problem, here is a test I am trying to run:

//start of Test.java document

import org.junit.*;
import static org.junit.Assert.*;

public class Test
{
        @Test
        public void testAddition()
        {
                assertTrue(true);
        }
}

//end of Test.java document

When I try to compile this program, command prompt gives me the following:

C:\...\currentDirectory> javac Test.java
Test.java:6: incompatible types
found   :  Test
required: java.lang.annotation.Annotation
      @Test
         ^
1 error

Does anyone know what the problem is?  It seems like it would be something very simple, but I can't figure it out.  I've already modified the class path to include the junit-4.5.jar file.

Re: javac won't accept @test

by Peter Niederwieser :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Either rename your test class to something other than "Test", or reference the annotation type by its fully qualified name ("@org.junit.Test").

Cheers,
Peter

Josheva wrote:
Hi.  I've successfully used JUnit 3 before, but I'm having trouble with JUnit 4.  Before I get into this, I'm using Windows Vista 64-bit, Java 1.6.0_16, and JUnit 4.5.

Simply put, javac won't accept the @Test flags that, I understand, are supposed to prefix every test method.  To illustrate my problem, here is a test I am trying to run:

//start of Test.java document

import org.junit.*;
import static org.junit.Assert.*;

public class Test
{
        @Test
        public void testAddition()
        {
                assertTrue(true);
        }
}

//end of Test.java document

When I try to compile this program, command prompt gives me the following:

C:\...\currentDirectory> javac Test.java
Test.java:6: incompatible types
found   :  Test
required: java.lang.annotation.Annotation
      @Test
         ^
1 error

Does anyone know what the problem is?  It seems like it would be something very simple, but I can't figure it out.  I've already modified the class path to include the junit-4.5.jar file.