一般我们会这样添加依赖项,这样Spring Boot会自动加载JUnit5:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
如果添加这样的依赖项后,也进行了MAVEN的更新,但是使用@SpringBootTest
却提示没有相关的类库可以引入。只需要将依赖项更改为下面这样,就可以正常找到类库。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
也就是去掉<scope>test</scope>