【发布时间】:2015-03-13 18:21:21
【问题描述】:
当我尝试import org.junit.Test 时,我遇到了The import org.junit.Test conflicts with a type defined in the same file 错误。
我可以毫无问题地导入Before 和After。
使用 @Test 注释时,Eclipse 无法识别它,因此不允许我以这种方式导入它。
进口:
import org.junit.Before;
import org.junit.After;
import org.junit.Test;
Maven 依赖:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
【问题讨论】:
-
你定义了一个名为Test的类吗?
-
是的,这似乎是问题所在。坦率地说,我很惊讶它无法通过路径区分差异
-
感谢您解决我的问题。一个教程出于某种原因写了
org.junit.jupiter.api.Test,Eclipse 没有给我任何建议。有谁知道他们为什么要这样做? (不作为问题发布,因为它不重要)