JUnit files not found

I added a JUnit jar to my classpath and it can easily find and run tests in the command window, but when I try to compile a test that I know, it cannot find anything to do with JUnit. I get the following error for each test class. I 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() {

Many thanks.

+3
source share
5 answers

Today I ran into this problem ...

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

  • I renamed my class to SomethingElseTest.java, and it pretty much fixed the problem.
  • , IDE "@Test" , @Test, .
+7

, , , , , , import org.junit.Test;, :

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

, import org.junit.*;.

+4

, , , Java .

, java -version . , , 1,4 , 1,5.

+1
source

I don't know if this will matter, but I'm used to seeing the @Test annotation above the declaration of the test method, for example:

@Test
public void testSomething()
{
   // 
}

My second guess is that another class file for Test imported somehow and not JUnit annotation.

0
source

It seems that you have a class Testsomewhere nearby and it has been imported. Try this code to make sure you are working with jUnit Testannotations:

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

Source: https://habr.com/ru/post/1796480/


All Articles