1. 整合JUnit
- 导入测试对应的starter
由于整合JUnit不需要导入其他特别的依赖,只需要导入两个springboot基础的依赖坐标
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
-
测试类使用@SpringBootTest修饰
需要说明的是,@SpringBootTest后面最好都加上classes= 启动类的字节码对象,避免运行出错。 -
使用自动装配的形式添加要测试的对象