新建SpringBoot项目后基本会包含下面引用,所以基本不用引入其他maven引用
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
新建测试类,添加SpringBootTest注解,后面的classes参数为SpringBoot启动类,在测试方法上加上@Test注解即可
@SpringBootTest(classes = TestredisApplication.class)
public class ProductServiceImplTest {
@Test
public void addInfoToRedis() {
productService.addInfoToRedis();
}
}
网友评论