SpringBoot 單元測試
依賴注入
引入依賴:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
這里引入了一個spring-boot-starter-test依賴猜绣,是springboot中寫單測所需要的。
在單元測試類上添加@RunWith(SpringRunner.class)纸兔、@SpringBootTest注解:
image.png