idea中出现类import org.junit.Test; 无法导入,但pom.xml中含有junit包,原因为:scope属性。
maven依赖中scope默认为compile,指定了依赖的作用范围。
- 作用范围包括,所在项目的测试、编译、运行、打包等生命周期
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope> //说明此jar包,只能在测试时使用。故可能出现编译时找不到该类。
</dependency>
修改为:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<!--此处test,表明 junit jar包只能出现在 test 环境下的classpath,
即 只能在标记为 “TestSources Root的 文件夹下”被调用, 而在“标记为Sources Root 的文件夹下”找不到其中的类-->
<scope>test</scope>
</dependency>
1222

被折叠的 条评论
为什么被折叠?



