SpringBoot使用JUnit进行测试

2022-07-27  本文已影响0人  天马行空_9f6e

新建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();

    }

}

上一篇 下一篇

猜你喜欢

热点阅读