Spring Boot Test
当你想测试写的代码,但是需要启动springboot容器,然而每次都要启动关闭,还要写到合适的类里,很麻烦
当然也有解决方案,使用springbootTest
1、引入包
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-test --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <version>2.7.5</version> <scope>test</scope> </dependency>
2、只需要使用一个注解即可启动springboot容器:@SpringBootTest
@SpringBootTest public class FirstTest { @Resource private PackagesInfoRepository packagesRepository; @Resource private DownloadURLRepository downloadURLRepository; @Test public void test() throws IOException { 。。。 }
}