简单记一下
单元测试时,导入了测试包,但是@SpringBootTest注解报红
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
在Libraries里根本找不到需要的测试类包
网上搜了很多方法,主要有①移动test位置到main中 ②<scope>test</scope> 注释掉 ③idea配置中删除 SpringBootTest.class 配置项
都没有解决问题
最后发现是导入包的版本问题
看一下自己的SpringBoot启动版本是多少,然后加上版本号就行了,例如我的是1.5.12.RELEASE
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>1.5.12.RELEASE</version>
<scope>test</scope>
</dependency>