1.引入单元测试的pom
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
2.在src/main下建立test包,mark directory as springboot resource root (有test目录不需要创建),注意Test类必须是和启动类在同一个包下,如下图:
3.在测试类写你的测试代码:
图下的注解代码:
@RunWith(SpringRunner.class),@org.junit.Test, @SpringBootTest