Eclipse+Maven+JUnit时The import org.junit cannot be resolved
开始学习JUnit,按官网的操作:https://github.com/junit-team/junit4/wiki/Download-and-Install
在Eclipse里配置了Maven:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
右键项目,选择Maven-Update project更新项目后,按官网Demo:https://github.com/junit-team/junit4/wiki/Assertions
增加类AssertTests
问题:
保存AssertTests后提示:
The import org.hamcrest cannot be resolved
The import org.junit cannot be resolved
检查BuildPath,Junit和hamcrest都已经在Maven下了:
解决办法:
在BuildPath中Add Library,选择Junit,版本选择JUnit4,Apply后问题解决