导入org.junit.Test不起作用

2 java import junit

当我尝试导入org.junit.Test时,出现“导入org.junit.Test与在同一文件中定义的类型冲突”错误。我可以导入之前和之后没有任何问题。当使用@Test批注时,Eclipse无法识别,因此不允许我以这种方式导入它。

进口:

import org.junit.Before;
import org.junit.After;
import org.junit.Test;
Run Code Online (Sandbox Code Playgroud)

Maven依赖关系:

 <dependencies>
<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>4.12</version>
  <scope>test</scope>
</dependency>
<dependency>
Run Code Online (Sandbox Code Playgroud)

小智 6

您可以确保该类文件名不是Test。重命名测试类为其他名称应该工作。类似的问题也曾在这里发表