POM导入
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>2.2.4.RELEASE</version>
</dependency>
在单元测试中加注解
@RunWith(SpringRunner.class)
//启动类的class
@SpringBootTest(classes = MySpringbootTest.class)