开发者

JUnit files not found

I've added the JUnit jar t开发者_JAVA技巧o my classpath, and it can find and run tests alright using the command window, but when I try and compile a test I know works, it can't seem to find anything to do with JUnit. I get the following error for every test class. Tested it on another computer and it works, but not on mine. Any ideas?

EstateAgentTest.java:25: incompatible types
found   : Test
required: java.lang.annotation.Annotation
    @Test public void rentable1() {

Thanks a lot.


I encountered this problem today...

Turns out calling my class name "Test.java" was a bad idea - it clashes with the @Test line above your test method. To fix:

  1. I renamed my class to SomethingElseTest.java, and it prettymuch fixed the issue.
  2. Note that my IDE did change my "@Test" line above the method to the new classname, but once I changed that back to @Test, everything was ok again.


This is probably a little late for the creator of the post, but for others that encounter the same problem, I had the exact same problem, and solved it with explicitly adding import org.junit.Test;, so my imports now look like this:

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

I have no idea why it didn't work with just import org.junit.*;.


The machine where it doesn't work seems to have older version of Java without annotations feature.

You can easily test that by entering java -version to your command line. It's probably 1.4 or so and you need at least 1.5 for annotations.


I don't know if it'll make a difference, but I'm used to seeing the @Test annotation above the test method declaration, like this:

@Test
public void testSomething()
{
   // 
}

My second guess is that there's another class file for Test imported somehow that is not the JUnit annotation.


Seems you have Test class somewhere around and it was imported. Try this code to be sure you are working with jUnit Test annotation:

@org.junit.Test 
void testSomething(){
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜